弹簧引导 当应用程序作为 jar 启动时,静态内部类未初始化



当我通过 intellij 启动我的 spring 启动应用程序时,以下类正确初始化,可以看到日志。 但是如果我从构建中再次运行 jar,MyCurrentTraceContext 似乎没有初始化,我也看不到输出中的日志。我确实需要这个带有我自定义逻辑的类来将一些参数运行到 MDC 中。有什么建议吗?

@Configuration
@ConditionalOnProperty(value="spring.sleuth.enabled", matchIfMissing=true)
@AutoConfigureBefore(TraceAutoConfiguration.class)
public class MyLogConfiguration extends SleuthLogAutoConfiguration {
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(WtrLogConfiguration.class);
@Configuration
@ConditionalOnClass(MDC.class)
@EnableConfigurationProperties(SleuthSlf4jProperties.class)
protected static class MySlf4jConfiguration extends Slf4jConfiguration {
@Bean
@ConditionalOnProperty(value = "spring.sleuth.log.slf4j.enabled", matchIfMissing = true)
@ConditionalOnMissingBean
@Override
public CurrentTraceContext slf4jSpanLogger() {
LOGGER.info("************ OVER WRITTING WTIH WtrCurrentTraceContext*******");
return new MyCurrentTraceContext(Slf4jCurrentTraceContext.create());
}
}
}

请与

@ComponentScan

在初学者类的顶部设置项目启动时需要扫描的路径。 在您的情况下,这将是:

@ComponentScan("myPackagePath.MyLogConfiguration.MySlf4jConfiguration.*"(

最新更新