【问题标题】:Autowire Beans with application-test.properties使用 application-test.properties 自动装配 Bean
【发布时间】:2018-07-16 10:12:06
【问题描述】:

我有以下测试类,我的 bean 总是根据我的 src 路径中的 application.properties 自动装配。

简单属性已正确自动装配(queueFrom、queueTo...),但属性 camelContext 与主体 application.properties 文件自动装配

我想用 测试路径

中的特定属性文件自动装配我的 bean

这是我的测试类的标题:

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@EnableAutoConfiguration
@TestPropertySource(locations = "classpath:application-north-connector-test.properties")
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class LifeRouteITTest extends CamelTestSupport {

  private NotifyBuilder notify;

  @Value("${route.lifefrom}")
  private String queueFrom;
  @Value("${route.lifeto}")
  private String queueTo;
  @Value("${expected.liferoute.file.path}/")
  private String expectedFilePath;
  @Value("${input.liferoute.file.path}/")
  private String inputFilePath;

  @Autowired
  private CamelContext camelContext;
}

感谢您的帮助。

【问题讨论】:

  • Spring boot 在 src/main/resources 下查找 application.properties。对于测试,它的 src/test/resources. Spring boot 会自动从这些位置获取文件。

标签: java spring spring-boot properties-file spring-camel


【解决方案1】:

您只需将测试属性放在application.properties 文件中,然后将其放在src/test/resources 中。测试属性将从那里自动加载。

【讨论】:

  • 运气好@marherbi?
猜你喜欢
  • 1970-01-01
  • 2021-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
  • 2012-08-11
  • 2013-06-29
相关资源
最近更新 更多