使用ejb和camel处理Web应用程序项目。 Camel能够找到定价服务的ejb,而不是建议服务。定位ejb bean时出错。应用程序是WAR包。
任何帮助表示赞赏!
我的无国籍的ejb:
@Stateless(name = "AdvisingServiceEJB")
@LocalBean
@TransactionManagement(TransactionManagementType.CONTAINER)
public class AdvisingServiceBean implements AdvisingServiceLocal {
/**
* Default constructor.
*/
public AdvisingServiceBean() {
// TODO Auto-generated constructor stub
}
@Override
public void process(Object obj) {
System.out
.println("Got from Advising EJB **********************************");
}
}
接口:
@Local
public interface AdvisingServiceLocal {
public void process(Object obj);
}
EJB-JAR:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" version="3.1">
<display-name>AdvisingService</display-name>
</ejb-jar>
routebuilder:
public class PaymentsRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from(
"mqjms:queue:queue:///testQueue?jmsMessageType=Text&exchangePattern=InOut")
.log("Message received")
// .to("ejb:PricingServiceEJB?method=processPricingRequest")
.to("ejb:AdvisingServiceEJB?method=process")
.log("Message processed");
}
}
路线与路线中评论的其他ejb完美配合。
camel context listener:
public class PaymentsContextListener extends
CamelServletContextListener<SimpleRegistry> {
private SimpleRegistry map;
@Resource(lookup = "java:jboss/TransactionManager")
TransactionManager txManager;
JtaTransactionManager manager;
@Override
public void contextInitialized(ServletContextEvent sce) {
// TODO Auto-generated method stub
super.contextInitialized(sce);
System.out.println("Context initialised");
}
@Override
protected SimpleRegistry createRegistry() throws Exception {
map = new SimpleRegistry();
map.put("mqjms", createMQComponent());
map.put("ejb", createEjbComponent());
return map;
}
/**
* Gets the {@link Map} that contains the data for the
* {@link SimpleRegistry}
*/
public Map<String, Object> getMap() {
return map;
}
private Component createMQComponent() {
MQXAConnectionFactory factory = new MQXAConnectionFactory();
try {
factory.setChannel("channel");
factory.setQueueManager("queuemanager");
factory.setTransportType(1);
factory.setHostName("hostname");
factory.setPort(12345);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assert factory != null;
JmsConfiguration config = new JmsConfiguration(factory);
config.setCacheLevel(0);
config.setTransacted(true);
config.setTransactionManager(getManager());
config.setDeliveryPersistent(true);
config.setConnectionFactory(factory);
return JmsComponent.jmsComponent(config);
}
private EjbComponent createEjbComponent() {
EjbComponent ejb = new EjbComponent();
Context initCtx = null;
try {
initCtx = new InitialContext();
initCtx = (Context) new InitialContext().lookup("java:comp/env");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ejb.setContext(initCtx);
// initCtx.lookup("AdvicingServiceEJB")
return ejb;
}
private JtaTransactionManager getManager() {
manager = new JtaTransactionManager(txManager);
return manager;
}
}
错误:
Caused by: [org.apache.camel.NoSuchBeanException - No bean could be found in the registry for: AdvisingServiceEJB]: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: AdvisingServiceEJB
at org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:85) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:78) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:68) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.component.bean.BeanProducer.process(BeanProducer.java:38) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:129) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87) [camel-core-2.15.2.jar:2.15.2]
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103) [camel-jms-2.15.2.jar:2.15.2]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:699) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:637) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:605) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:308) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:226) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1144) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1136) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1033) [spring-jms-4.1.6.RELEASE.jar:4.1.6.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_45]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_45]
的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>PaymentService</display-name>
<context-param>
<param-name>name</param-name>
<param-value>PaymentsCamel</param-value>
</context-param>
<context-param>
<param-name>routeBuilder-PaymentsRoute</param-name>
<param-value>camel.router.PaymentsRouteBuilder</param-value>
</context-param>
<listener>
<listener-class>camel.router.PaymentsContextListener</listener-class>
</listener>
</web-app>