
[英]How to initialize spring-boot WebMvc? (ServletContext always null)
[英]ProducerTemplate is always null with camel and spring-boot
我需要将Camel与spring-boot集成,以实现相同的目的,我正在使用下面的代码来构建ProducerTemplate
进行bean集成,但是ProducerTemplate
始终为NULL。
Java代码
@RestController
public class TestController implements ProductSummaryApi {
@EndpointInject(uri = "direct:test")
ProducerTemplate testRoute;
@RequestMapping(value = "/v1/test", method = RequestMethod.GET)
public String test(){
System.out.println("Route: " + testRoute);
return "Test";
}
}
行System.out.println("Route: " + testRoute);
打印NULL
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.21.0</version>
</dependency>
任何提示表示赞赏,为什么应用程序无法构建ProducerTemplate
对象。
ProducerTemplate
,则@Produce
依赖Spring进行Producer模板的依赖注入。 这意味着自动连接生产者模板的服务必须将自己注册为Bean。 @Component
或其子类型进行注释。 ProducerTemplate
并已与上下文关联(假设您已经使用@Bean
注册为bean),请使用@Produce(context="contextName1")
。 检查您的组件扫描路径。 那主要是你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.