小编coo*_*avi的帖子

有没有办法获取 SpringBoot 应用程序中加载的属性文件列表?

当我尝试执行mvn clean install. 作为构建的一部分,我们编译多个组件,最后使用wiremock 执行功能测试。它应该从功能测试配置文件中选择特定配置,并且应该从 application.properties 文件中选择默认属性。但由于某种原因,相同的代码无法找到这些文件中提到的属性。所以,只是想知道是否可以以某种方式获取在wiremock 期间加载的属性文件列表?这将提供一些线索,说明为什么没有选择预期的属性文件?

所有属性文件都位于内部:

src/main/resources
Run Code Online (Sandbox Code Playgroud)

并且,从测试课开始。

@ContextConfiguration(classes = SampleFTConfiguration.class)
public class SampleControllerTest{
//test method
}

@ComponentScan("com.xxx.xxx.xxx.ft")
@PropertySource("classpath:application-test.properties")
public class  SampleFTConfiguration{


}
Run Code Online (Sandbox Code Playgroud)

注意:我不希望任何人解决这个问题,我只想知道,我们是否可以获得加载的属性文件的名称?

java properties-file spring-boot wiremock spring-boot-2

7
推荐指数
1
解决办法
1万
查看次数

如何启用 Spring Cloud Contract Wiremock 服务器日志记录?

根据官方文档How to Debug,我需要将以下内容添加到属性文件中以启用日志记录

logging.level.org.apache.http.wire=DEBUG
logging.level.com.github.tomakehurst.wiremock=DEBUG
Run Code Online (Sandbox Code Playgroud)

但是,当请求发送到wiremock服务器时,我在控制台上看不到任何可见的日志。我500 Internal Server Error只得到特定的平台。因此,为了排除故障,我尝试在请求到达wiremock服务器时拦截活动。

在我的 pom 文件中

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-test</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
  <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-webflux</artifactId>
  <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我还尝试添加logback-test.xml包含以下内容的文件。但是,这也没有记录任何内容。

<logger name="com.github.tomakehurst.wiremock" level="DEBUG"/> 
<logger name="wiremock.org" level="DEBUG"/> 
<logger name="WireMock" level="DEBUG"/> 
<logger name="/" level="DEBUG"/> 
Run Code Online (Sandbox Code Playgroud)

我的测试班

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
    classes = MyApplication.class)
@AutoConfigureMockMvc
@TestPropertySource(
    locations = "/application-integration-test.properties"
)
@AutoConfigureWireMock(port = 0)
@AutoConfigureWebTestClient(timeout = "100000")
public class MyApplicationTest {

  private WebTestClient client;

  @LocalServerPort
  private int port;


  @Before
  public void …
Run Code Online (Sandbox Code Playgroud)

java logging spring-test wiremock spring-cloud-contract

3
推荐指数
1
解决办法
2331
查看次数