Java EE 6 + JPA - 异常:消息驱动 Bean 无法被管理 bean
我创建了一个 企业应用程序
CustomerApp
,它还生成了两个项目 CustomerApp-ejb
和 CustomerApp-war
。在 CustomerApp-ejb
中,我创建了一个 SessionBean 调用 CustomerSessionBean.java
,如下所示。
package com.customerapp.ejb;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
@LocalBean
public class CustomerSessionBean {
@PersistenceContext(unitName = "CustomerApp-ejbPU")
private EntityManager em;
public void persist(Object object) {
em.persist(object);
}
}
现在我可以很好地部署 CustomerApp-war
了。但是,一旦我创建了消息驱动 Bean,我就无法再部署 CustomerApp-war
了。当我创建 NotificationBean.java
(消息驱动 bean)时,在 项目目标
选项中,我单击添加,并为 NotificationQueue
>目标名称和目标类型
是队列。下面是代码
package com.customerapp.mdb;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;
@MessageDriven(mappedName = "jms/NotificationQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class NotificationBean implements MessageListener {
public NotificationBean() {
}
public void onMessage(Message message) {
}
}
服务器日志显示消息驱动Bean不能被管理bean
。好吧,我并不是说它是托管 bean。我的代码中没有 @ManagedBean
???
编辑:这是服务器日志
[#|2010-06-03T10:02:08.172-0400|SEVERE|glassfishv3.0|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=24;_ThreadName=Thread-1;|Exception while loading the app org.glassfish.deployment.common.DeploymentException: Message Driven Beans can't be Managed Beans
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:169)
at org.glassfish.kernel.event.EventsImpl.send(EventsImpl.java:125)
at org.glassfish.internal.data.ApplicationInfo.load(ApplicationInfo.java:224)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:338)
at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:637)
Caused by: org.jboss.weld.DefinitionException: Message Driven Beans can't be Managed Beans
at org.jboss.weld.bean.SessionBean.checkEJBTypeAllowed(SessionBean.java:313)
at org.jboss.weld.bean.SessionBean.initialize(SessionBean.java:122)
at org.jboss.weld.bootstrap.AbstractBeanDeployer.deploy(AbstractBeanDeployer.java:111)
at org.jboss.weld.bootstrap.BeanDeployment.deployBeans(BeanDeployment.java:151)
at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:367)
at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:167)
... 30 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 GlassFish 3.0 中的一个错误,已在 3.0.1 中修复。
beans.xml
(但这会禁用 CDI)在最初的答案下方:
CustomerApp-ejb
中?CustomerApp-war
是什么意思?您应该部署企业应用程序 (CustomerApp
)。This is a bug in GlassFish 3.0 which is fixed in 3.0.1.
beans.xml
(but this will disable CDI)Below the initial answer:
CustomerApp-ejb
?CustomerApp-war
just fine? You're supposed to deploy the Enterprise application (CustomerApp
).