arthas-spring-boot-starter support appName. #1562

pull/1585/head^2
hengyunabc 4 years ago
parent 288b1eee0c
commit 1eafe43b0a

@ -12,6 +12,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.ConfigurableEnvironment;
import com.taobao.arthas.agent.attach.ArthasAgent;
@ -25,6 +26,9 @@ import com.taobao.arthas.agent.attach.ArthasAgent;
public class ArthasConfiguration {
private static final Logger logger = LoggerFactory.getLogger(ArthasConfiguration.class);
@Autowired
ConfigurableEnvironment environment;
@ConfigurationProperties(prefix = "arthas")
@ConditionalOnMissingBean
@Bean
@ -36,7 +40,16 @@ public class ArthasConfiguration {
@Bean
public ArthasAgent arthasAgent(@Autowired Map<String, String> arthasConfigMap,
@Autowired ArthasProperties arthasProperties) throws Throwable {
arthasConfigMap = StringUtils.removeDashKey(arthasConfigMap);
arthasConfigMap = StringUtils.removeDashKey(arthasConfigMap);
/**
* @see org.springframework.boot.context.ContextIdApplicationContextInitializer#getApplicationId(ConfigurableEnvironment)
*/
String appName = environment.getProperty("spring.application.name");
if (arthasConfigMap.get("appName") == null && appName != null) {
arthasConfigMap.put("appName", appName);
}
// 给配置全加上前缀
Map<String, String> mapWithPrefix = new HashMap<String, String>(arthasConfigMap.size());
for (Entry<String, String> entry : arthasConfigMap.entrySet()) {

@ -16,6 +16,8 @@ public class ArthasProperties {
private String tunnelServer;
private String agentId;
private String appName;
/**
* report executed command
*/
@ -105,4 +107,12 @@ public class ArthasProperties {
this.sessionTimeout = sessionTimeout;
}
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
}

@ -6,5 +6,6 @@ arthas.ip=127.0.0.1
# seconds
arthas.sessionTimeout=1800
#arthas.appName=demoapp
#arthas.tunnelServer=ws://127.0.0.1:7777/ws
#arthas.agentId=mmmmmmyiddddd

Loading…
Cancel
Save