Reputation: 79
I have start routes in startup class and create a new CamelContextBean class because of This is a CDI injectable bean that will hold a reference to a CamelContext instance.
CamelContextBean :
public class CamelContextBean {
private CamelContext camelContext;
public CamelContext getCamelContext() {
return camelContext;
}
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
}
Startup class:
@Singleton
@Startup
public class BootStrap {
private static CamelContext camelContext;
private CamelContextBean camelContextBean = new CamelContextBean();
@PostConstruct
public void init() throws Exception {
camelContext = new DefaultCamelContext();
try {
camelContext.addRoutes(new MyRoute1());
camelContext.addRoutes(new MyRoute2());
camelContext.start();
camelContextBean.setCamelContext(camelContext);
} catch (Exception e) {
e.printStackTrace();
}
@Produces
public CamelContextBean getCamelContextService() {
return camelContextService;
}
I want to use the camelContextBean in same jar by inject it.
@Stateless
public class TestService {
@Inject
CamelContextBean camelContextService;
public void connectRoute(){
CamelContext camelContext = camelContextService.getCamelContext();
...
...
}
I installed this jar in maven repository. Try to use as dependency in war project and use this TestService as a ejb service.
@EJB
TestService testService
When build the war project that all the routes are started. But cannot complete the build, it given Failed to start TestService because of that error in title.Can I have a solution for this problem?
Upvotes: 1
Views: 1347
Reputation: 28665
You can implement this with the above configuration. However, you may need to implement Camel CDI with the wildfly 9.0.2 pach. I have given detail level asnwer in the How to use same CamelContext in multiple jar on the same war This might help you.
Upvotes: 1