众妙之门

业精于勤,荒于嬉;行成于思,毁于随

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在使用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"})

 

posted on 2023-12-11 10:13  xuanm  阅读(102)  评论(0编辑  收藏  举报