How do I catch BeanCreationException in Apache Camel route initialization to allow my Spring application to start anyway? -
i using apache camel , defined route receiving inputs 2 queues located on 2 distinct servers. want ideally consume both server want able run application when 1 of 2 destinations down.
here's route:
try { from("mccdsjmsrequest1:queue:{{mccds.queues.in}}").to("direct:apollomccdsroute"); } catch (exception e){ // debug line system.out.println("ms1 not reachable"); e.printstacktrace(); } try { from("mccdsjmsrequest2:queue:{{mccds.queues.in}}").to("direct:apollomccdsroute"); } catch (exception e){ // debug line system.out.println("ms2 not reachable"); e.printstacktrace(); } from("direct:apollomccdsroute").routeid("apollomccdsroute") // main route starts here...
i declare beans here:
@bean public jndiobjectfactorybean mccdsjmsconnectionfactory1() { jndiobjectfactorybean cf = new jndiobjectfactorybean(); cf.setjndienvironment(prodmccdsjndiproperties.getjndi1()); cf.setjndiname(jndiname1); return cf; } @bean public jndiobjectfactorybean mccdsjmsconnectionfactory2(){ jndiobjectfactorybean cf = new jndiobjectfactorybean(); cf.setjndienvironment(prodmccdsjndiproperties.getjndi2()); cf.setjndiname(jndiname2); return cf; } @inject private camelcontext camelcontext; @bean public jmscomponent mccdsjmsrequest1() { jmscomponent ac = new jmscomponent(camelcontext); ac.setconnectionfactory((connectionfactory) mccdsjmsconnectionfactory1().getobject()); ac.setconcurrentconsumers(5); return ac; } @bean public jmscomponent mccdsjmsrequest2(){ jmscomponent ac = new jmscomponent(camelcontext); ac.setconnectionfactory((connectionfactory) mccdsjmsconnectionfactory2().getobject()); ac.setconcurrentconsumers(5); return ac; }
if 1 of connection factory not reachable application doesn't start. catch ignore exception:
o.s.b.f.s.defaultlistablebeanfactory : bean creation exception on non-lazy factorybean type check: org.springframework.beans.factory.beancreationexception: error creating bean name 'mccdsjmsconnectionfactory2' defined in class path resource [ca/bell/it/spa/uim/apollo/maximo/config/mccds/prodmccdsjmsconfiguration.class]: invocation of init method failed; nested exception javax.naming.communicationexception [root exception java.net.connectexception: t3://sometestserverip: destination unreachable; nested exception is: java.net.connectexception: connection refused (connection refused); no available router destination]
try set lookuponstartup
false. (add cf.setlookuponstartup(false)
mccdsjmsconnectionfactory1
, mccdsjmsconnectionfactory2
bean definitions.)
also check thread: http://forum.spring.io/forum/spring-projects/batch/95620-jndi-lookup
Comments
Post a Comment