简体   繁体   English

具有application-test.properties的自动装配Bean

[英]Autowire Beans with application-test.properties

I have the following Test class, and my beans are always autowired according to the application.properties in my src path . 我有以下Test类,并且我的bean总是根据src path中的application.properties自动接线。

The simple attributes are correctly autowired (queueFrom, queueTo...) but the attribute camelContext is autowired with the principal application.properties file 简单的属性已正确自动连接(queueFrom,queueTo ...),但属性camelContext已与主体application.properties文件自动连接

I want to autowire my beans with a specific properties file in test path 我想用测试路径中的特定属性文件自动连接我的bean

This is the header of my Test class: 这是我的Test类的标题:

@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;
}

Thanks for your help. 谢谢你的帮助。

You just need to put your test properties in an application.properties file and place it in src/test/resources . 您只需要将测试属性放在application.properties文件中,然后将其放在src/test/resources The test properties would be loaded from there automatically. 测试属性将自动从那里加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM