Hi,

I am trying to bootstrap camel + spring with Wildfly.
My first solution (see bellow) works fine without Spring but I need to call
context.addRoutes from my code if I want to register my route:

@Singleton
@Startup
public class BootStrap {

    private Logger logger = LoggerFactory.getLogger(BootStrap.class);

    @Inject
    private CdiCamelContext camelContext;

    @PostConstruct
    public void init() {
        logger.info("-> Creating camel context and registering routes.");
        registerRoutes();  // <-- i want to avoid this line!
        camelContext.start();
        logger.info("-> Camel context created and routes started.");
    }

    @PreDestroy
    public void stop() {
        camelContext.stop();
        logger.info("-> Camel context stopped.");
    }

    private void registerRoutes() {
         camelContext.addRoutes(new TimerRouteBuilder());
    }
}


I would like to use camel + spring together in a EE container like Wildfly
because my real queue sits in Wildfly. So I modified my original code but it
does not work:


@Singleton
@Startup
public class BootStrap {

    private Logger logger = LoggerFactory.getLogger(BootStrap.class);
    private CamelContext camelContext;

    @PostConstruct
    public void init() {
        logger.info("-> Creating camel context and registering routes.");

        ApplicationContext context = new
ClassPathXmlApplicationContext("conf/beans.xml");
        camelContext = context.getBean("camelContext", CamelContext.class);

        //registerRoutes();
        camelContext.start();
        logger.info("-> Camel context created and routes started.");
    }

    @PreDestroy
    public void stop() {
        camelContext.stop();
        logger.info("-> Camel context stopped.");
    }
}


bean.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:p="http://www.springframework.org/schema/p";
       xmlns:context="http://www.springframework.org/schema/context";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
               http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
           http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd";>

    <context:component-scan base-package="a.b.c.camel.route" />

    <camelContext id="camelContext"
xmlns="http://camel.apache.org/schema/spring"; streamCache="true">
        <package>a.b.c.camel.route</package>
    </camelContext>

</beans>

I can deploy this ear into Wildfly without any error or warning but camel
does not start my route.

According to the log camel is started but my beans.xml file is not used (I
guess spring is not initialized):
...
[org.apache.camel.impl.converter.DefaultTypeConverter] Loaded 183 type
converters
[org.apache.camel.impl.DefaultRuntimeEndpointRegistry] Runtime endpoint
registry is in extended mode gathering usage statistics of all incoming and
outgoing endpoints (cache limit: 1000)
[org.apache.camel.spring.SpringCamelContext] AllowUseOriginalMessage is
enabled. If access to the original message is not needed, then its
recommended to turn this option off as it may improve performance.
[org.apache.camel.impl.DefaultStreamCachingStrategy] StreamCaching in use
with spool directory:
/tmp/camel/camel-tmp-8003df7d-fa2b-4e9f-a772-b03bcc275750 and rules: [Spool
> 128K body size]
[org.apache.camel.spring.SpringCamelContext] Total 0 routes, of which 0 is
started.
[org.apache.camel.spring.SpringCamelContext] Apache Camel 2.16.1
(CamelContext: camelContext) started in 0.170 seconds
[org.apache.camel.spring.SpringCamelContext] Apache Camel 2.16.1
(CamelContext: camelContext) is starting
[org.apache.camel.spring.SpringCamelContext] Total 0 routes, of which 0 is
started.
[org.apache.camel.spring.SpringCamelContext] Apache Camel 2.16.1
(CamelContext: camelContext) started in 0.001 seconds
11:36:58,376 INFO  [a.b.c.camel.BootStrap] (ServerService Thread Pool -- 75)
-> Camel context created and routes started.





--
View this message in context: 
http://camel.465427.n5.nabble.com/camel-in-EE-container-tp5776589.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to