【问题标题】:Is there a way we can load properties from src/test/resources/application.properties in spring boot test?有没有办法在春季启动测试中从 src/test/resources/application.properties 加载属性?
【发布时间】:2021-09-15 17:10:27
【问题描述】:
    @ExtendWith(SpringExtension.class)
@WebMvcTest(MyClass.class)
@TestPropertySource(locations="classpath:application-test.yml")

//像这样的吗?

【问题讨论】:

    标签: spring-boot spring-mvc-test


    【解决方案1】:

    这应该仍然能够在您的应用程序的测试文件中找到属性:

    @Autowired
    private Environment env;
    
    // Load data
    String data = env.getProperty("some.property")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-23
      • 2018-01-21
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      相关资源
      最近更新 更多