在使用SpringBootTest测试的时候,如果配置文件里面使用了属性判断,使用logback-spring.xml时,有下面的配置:
<if condition='!property("spring.profiles.active").contains("dev")'> <then> <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <destination>${logstash.host}</destination> <connectionStrategy> <roundRobin> <connectionTTL>5 seconds</connectionTTL> </roundRobin> </connectionStrategy> <writeBufferSize>163840</writeBufferSize> <reconnectionDelay>1 second</reconnectionDelay> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder"> <provider class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.logstash.TraceIdJsonProvider"> </provider> <customFields>{"active":"${spring.profiles.active}"}</customFields> </encoder> </appender> </then> </if>
在这个即使使用了@ActiveProfiles("dev"),读取不到配置,可以增加测试属性或注解
1.IDEA增加调试配置
2.增加调试注解
@TestPropertySource(properties = {"spring.profiles.active=dev"})
标签:spring,配置,dev,SpringBootTest,测试,active From: https://www.cnblogs.com/grasp/p/17893776.html