gpt4 book ai didi

java - GlassFish 2.1 上的 EJB 依赖项未正确连接(注入(inject))

转载 作者:行者123 更新时间:2023-12-01 15:20:08 27 4
gpt4 key购买 nike

出于某种原因,我应该使用旧的 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();
//.......
}
}

触发处理器:

@Stateless
public class TriggerProcessor {
public void proceess() {
//....
}
}

我尚未创建部署描述符。据我了解,如果我使用注释和 EJB 版本从 3.0 开始,则没有必要

部署时出现以下异常:

[#|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
|#]

我尝试使用 @EJB(beanName="TriggerProcessor")public class TriggerProcessor {.. 注释 private TriggerProcessor triggerService; @Stateless(name="TriggerProcessor") 但没有帮助。

实际上,这在最新的 Glassfish 3.1 上完美运行。但正如我所说,我应该使用 GF 2.1.1。

感谢任何帮助!

最佳答案

它无法工作,因为 GlassFish 2 不支持 EJB 3.1。 TriggerProcessor 仅提供无接口(interface) View ,因为它不实现任何接口(interface)。您必须为 TriggerProcessor 提供一个接口(interface),以便与 EJB 3.0 兼容。

仅 EJB 3.1 支持无接口(interface) View 。请参阅http://docs.oracle.com/cd/E19776-01/820-4496/beahm/index.html以及 JSR 318 规范的 1.2 EJB 3.1 中的新增功能 章节。

关于java - GlassFish 2.1 上的 EJB 依赖项未正确连接(注入(inject)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11051338/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com