2022-07-15 22:37:32 +08:00
# Arthas Spring Boot Starter
2020-07-01 11:27:31 +08:00
2022-07-15 22:37:32 +08:00
::: tip
只支持 spring boot 2
:::
2020-07-01 11:27:31 +08:00
最新版本:[查看](https://search.maven.org/search?q=arthas-spring-boot-starter)
2022-07-15 22:37:32 +08:00
配置 maven 依赖:
2020-07-01 11:27:31 +08:00
```xml
< dependency >
< groupId > com.taobao.arthas< / groupId >
< artifactId > arthas-spring-boot-starter< / artifactId >
< version > ${arthas.version}< / version >
< / dependency >
```
2022-07-15 22:37:32 +08:00
应用启动后, spring 会启动 arthas, 并且 attach 自身进程。
2020-07-01 11:27:31 +08:00
2022-07-15 22:37:32 +08:00
::: tip
一键创建包含 Arthas Spring Boot Starter 的工程:< a href = "https://start.aliyun.com/bootstrap.html/#!dependencies=arthas" target = "_blank" > 点击< / a >
:::
2020-09-18 21:51:34 +08:00
2022-08-09 18:42:39 +08:00
## 配置属性
2020-07-01 11:27:31 +08:00
2022-07-15 22:37:32 +08:00
比如,通过配置 tunnel server 实现远程管理:
2020-07-01 11:27:31 +08:00
```
2020-07-08 10:38:57 +08:00
arthas.agent-id=hsehdfsfghhwertyfad
2020-07-01 11:27:31 +08:00
arthas.tunnel-server=ws://47.75.156.201:7777/ws
```
全部支持的配置项:[参考](https://github.com/alibaba/arthas/blob/master/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java)
2022-07-15 22:37:32 +08:00
::: tip
默认情况下, arthas-spring-boot-starter 会禁掉`stop`命令。
:::
2021-06-10 20:40:47 +08:00
2020-09-03 16:30:01 +08:00
参考:[Arthas Properties](arthas-properties.md)
2020-07-01 11:27:31 +08:00
2022-08-09 18:42:39 +08:00
## 查看 Endpoint 信息
2020-07-01 11:27:31 +08:00
2022-07-15 22:37:32 +08:00
::: tip
需要配置 spring boot 暴露 endpoint: [参考](https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints)
:::
2020-07-09 11:23:45 +08:00
2022-07-15 22:37:32 +08:00
假定 endpoint 端口是 8080, 则通过下面 url 可以查看:
2020-07-01 11:27:31 +08:00
http://localhost:8080/actuator/arthas
```
{
"arthasConfigMap": {
2020-07-01 11:45:30 +08:00
"agent-id": "hsehdfsfghhwertyfad",
2020-07-01 11:27:31 +08:00
"tunnel-server": "ws://47.75.156.201:7777/ws",
}
}
```
2022-08-09 18:42:39 +08:00
## 非 spring boot 应用使用方式
2020-07-01 11:27:31 +08:00
2022-07-15 22:37:32 +08:00
非 Spring Boot 应用,可以通过下面的方式来使用:
2020-07-01 11:27:31 +08:00
```xml
< dependency >
< groupId > com.taobao.arthas< / groupId >
< artifactId > arthas-agent-attach< / artifactId >
< version > ${arthas.version}< / version >
< / dependency >
2020-07-30 15:06:20 +08:00
< dependency >
< groupId > com.taobao.arthas< / groupId >
< artifactId > arthas-packaging< / artifactId >
< version > ${arthas.version}< / version >
< / dependency >
2020-07-01 11:27:31 +08:00
```
```java
import com.taobao.arthas.agent.attach.ArthasAgent;
public class ArthasAttachExample {
2022-07-15 22:37:32 +08:00
2020-07-01 11:27:31 +08:00
public static void main(String[] args) {
ArthasAgent.attach();
}
}
2020-11-27 11:06:01 +08:00
```
也可以配置属性:
```java
HashMap< String , String > configMap = new HashMap< String , String > ();
configMap.put("arthas.appName", "demo");
configMap.put("arthas.tunnelServer", "ws://127.0.0.1:7777/ws");
ArthasAgent.attach(configMap);
```
2022-07-15 22:37:32 +08:00
::: warning
注意配置必须是`驼峰`的,和 spring boot 的`-`风格不一样。spring boot 应用才同时支持`驼峰` 和 `-` 风格的配置。
:::