SpringBootTest測試配置

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章