1

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.

  • java 1.8
  • apache camel 2.16.2
  • wildfly 9.0.2
  • ejb 3

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?

Kenster
  • 23,465
  • 21
  • 80
  • 106
coolD
  • 79
  • 1
  • 10

1 Answers1

1

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.

Community
  • 1
  • 1
kds
  • 28,155
  • 9
  • 38
  • 55
  • 1
    This is really useful for me.Thank you kds. – coolD Mar 29 '16 at 10:21
  • 1
    @kds, I'm getting the same issue with wildfly 10.1.0. This patch is not compatible with that and this is not resolved with 4.8.0 patch in there. So, how to do this with 10.1.0 Final. – ironwood Oct 03 '17 at 06:59
  • Hi @namalfernandolk you can use the https://github.com/wildfly-extras/wildfly-camel/releases/tag/4.9.0 for the wildfly 10.1.0. Also use the below link to access the latest camel patch https://github.com/wildfly-extras/wildfly-camel/releases – kds Jun 24 '19 at 08:31