出于某种原因,我应该使用旧的EJB容器GlassFish 2.1.1。 (通过Java EE 5和EJB 3.0认证)。项目结构如下:
MDB:
@MessageDriven(
mappedName = "jms/Queue",
activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue")
})
public class TriggerMBean implements MessageListener {
@EJB
private TriggerProcessor triggerService;
public void onMessage(Message message) {
//.......
triggerService.process();
//.......
}
}
TriggerProcessor:
@Stateless
public class TriggerProcessor {
public void proceess() {
//....
}
}
我没有创建部署描述符。据我所知,如果我使用从3.0开始的注释和EJB版本
,则没有必要部署时,异常如下:
[#|2012-06-15T15:55:50.290+0300|SEVERE|sun-appserver2.1|javax.enterprise.system.container.ejb.mdb|_ThreadID=42;_ThreadName=p: thread-pool-1; w: 61;_RequestID=824fc411-7772-42cc-aeee-9a8d9b451dbf;|com.sun.enterprise.InjectionException
com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref fi.prh.novus.sync.consumer.TriggerMBean/triggerService@jndi: fi.prh.novus.sync.service.TriggerProcessor@null@fi.prh.novus.sync.service.TriggerProcessor@Session@null into class fi.prh.novus.sync.consumer.TriggerMBean
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:387)
at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:206)
at com.sun.enterprise.util.InjectionManagerImpl.injectInstance(InjectionManagerImpl.java:127)
at com.sun.ejb.containers.MessageBeanContainer.createMessageDrivenEJB(MessageBeanContainer.java:711)
at com.sun.ejb.containers.MessageBeanContainer.access$100(MessageBeanContainer.java:109)
at com.sun.ejb.containers.MessageBeanContainer$MessageBeanContextFactory.create(MessageBeanContainer.java:492)
at com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:199)
at com.sun.ejb.containers.MessageBeanContainer._getContext(MessageBeanContainer.java:555)
at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:1731)
at com.sun.ejb.containers.MessageBeanContainer.beforeMessageDelivery(MessageBeanContainer.java:1008)
at com.sun.ejb.containers.MessageBeanListenerImpl.beforeMessageDelivery(MessageBeanListenerImpl.java:70)
at com.sun.enterprise.connectors.inflow.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:135)
at $Proxy86.beforeDelivery(Unknown Source)
at com.sun.messaging.jms.ra.OnMessageRunner.run(OnMessageRunner.java:245)
at com.sun.enterprise.connectors.work.OneWork.doWork(OneWork.java:77)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: javax.naming.NameNotFoundException: fi.prh.novus.sync.service.TriggerProcessor#fi.prh.novus.sync.service.TriggerProcessor not found
at com.sun.enterprise.naming.TransientContext.doLookup(TransientContext.java:216)
at com.sun.enterprise.naming.TransientContext.lookup(TransientContext.java:188)
at com.sun.enterprise.naming.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:74)
at com.sun.enterprise.naming.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:111)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:409)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.naming.NamingManagerImpl.lookup(NamingManagerImpl.java:951)
at com.sun.enterprise.naming.java.javaURLContext.lookup(javaURLContext.java:173)
at com.sun.enterprise.naming.SerialContext.lookup(SerialContext.java:407)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:287)
... 15 more
|#]
我尝试使用private TriggerProcessor triggerService;
和@EJB(beanName="TriggerProcessor")
public class TriggerProcessor {..
注释@Stateless(name="TriggerProcessor")
,但没有帮助。
实际上,这完全适用于最新的Glassfish 3.1。但正如我所说,我应该使用GF 2.1.1。
任何帮助表示赞赏!
答案 0 :(得分:1)
由于GlassFish 2不支持EJB 3.1,因此无法正常工作。 TriggerProcessor
ony提供了无接口视图,因为它没有实现任何接口。您必须提供TriggerProcessor
符合EJB 3.0的接口。
只有EJB 3.1支持无接口视图。请参阅JSR 318规范的http://docs.oracle.com/cd/E19776-01/820-4496/beahm/index.html和 1.2 EJB 3.1中的新内容
章节。