【发布时间】:2017-03-30 12:45:00
【问题描述】:
我在骆驼路线的单元测试中有以下内容:
RouteUnitTest.java
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RouteUnitTestConfig.class})
public class RouteUnitTest extends CamelTestSupport {
@Autowired
MQProperties mqProps;
@Autowired
Route route;
@Produce(uri="...")
ProducerTempalte template;
@Test
//rest of test class
}
MQProperties 对象从属性文件中提取属性,对于单元测试,它读取 application-unit-test.properties 文件,该文件使用 SEDA 端点进行单元测试。我似乎无法在 @Produce 标签中正确表达;我想将 ProducerTemplates uri 设置为 mqProps.getReceiveQueue(),但是在我尝试过的格式中,我得到了一个关于为生产者设置默认端点的异常。我知道应该传入的值不是问题,调用 template.send(mqProps.getReceiveQueue(), exchange);例如工作得很好。我尝试了以下格式:
@Produce(uri="#{@mqProps.getReceiveQueue}")
@Produce(uri="{{mqProps.getReceiveQueue}}")
@Produce(uri="#{mqProps.getReceiveQueue}")
这些都抛出了提到的异常。我是不是把 EL 格式弄错了,还是自动装配有问题?即也许当生产者 uri 的东西都被连接起来时,对象还没有被填充?我在这方面找不到太多其他内容,Camel 资源更多地讨论了 Bean 注入等,但到目前为止我在 @Produce 注释上看到的任何资源通常都使用硬编码字符串,或者直接从属性文件中读取
【问题讨论】:
标签: java spring spring-boot apache-camel