一、前言
spring boot 2.2.x release note 说明:
1.1 HttpTrace:
由于Spring Boot Actuator使用HttpTrace消耗资源并不支持集群,在Spring Boot 2.2 Release Notes开始已经默认禁用了,要启用HTTP跟踪,实现HttpTraceRepository或AuditEventRepository重新打开这些功能。
1.2 Tomcat Thread:
Spring Boot 2.2 Release Notes开始已经默认禁用了,从而节省了大约2MB的堆。
二、解决方案
2.1 HttpTrace:
a. 了解下 Spring Cloud Sleuth + Zipkin OR Skywalking
b. 要启用HTTP跟踪,实现HttpTraceRepository或AuditEventRepository重新打开这些功能。(PS:但是消耗资源并不支持集群)
import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.trace.http.HttpTraceProperties;
import org.springframework.boot.actuate.trace.http.HttpTrace;
import org.springframework.boot.actuate.trace.http.HttpTraceRepository;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@Configuration
@ConditionalOnWebApplication
@ConditionalOnProperty(prefix = "management.trace.http", name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(HttpTraceProperties.class)
@AutoConfigureBefore(HttpTraceAutoConfiguration.class)
class TraceConfig {
private List<HttpTrace> list = new CopyOnWriteArrayList<HttpTrace>();
@Bean
@ConditionalOnMissingBean(HttpTraceRepository.class)
public HttpTraceRepository traceRepository() {
return new HttpTraceRepository() {
@Override
public List<HttpTrace> findAll() {
return list;
}
@Override
public void add(HttpTrace trace) {
if (list.size() > 99){
list.remove(0);
}
list.add(trace);
}
};
}
}
2.2 Tomcat Thread :
server:
tomcat:
mbeanregistry:
enabled: true