我正在尝试将JMS队列注入到无状态EJB中。我的代码看起来是这样的:
@Stateless
public class JmsSender implements Serializable {
private static final long serialVersionUID = 1L;
@Resource(mappedName="java:/ConnectionFactory")
private ConnectionFactory connectionFactory;
@Resource(mappedName="queue/TestQueue")
private Queue queue;
public void doIt(String nachricht){
try{
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer=session.createProducer(queue);
TextMessage message = session.createTextMessage("Queue-Message: " +nachricht);
messageProducer.send(message);
}catch (JMSException e) {
e.printStackTrace();
}
}
}
当我试图将其部署到应用程序服务器(Wildfly 9.0.2)时,引发了以下异常
09:05:11,409 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "JMSProject.war")]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.JMSProject.JMSProject.env.\"abc.jms.JmsSender\".queue is missing [jboss.naming.context.java.module.JMSProject.JMSProject.env.queue.TestQueue]"]}
09:05:11,455 INFO [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "JMSProject.war" (runtime-name : "JMSProject.war")
09:05:11,456 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0184: New missing/unsatisfied dependencies:
service jboss.naming.context.java.module.JMSProject.JMSProject.env.queue.TestQueue (missing) dependents: [service jboss.naming.context.java.module.JMSProject.JMSProject.env."abc.jms.JmsSender".queue]
09:05:11,582 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
09:05:11,583 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
09:05:11,583 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: WildFly Full 9.0.2.Final (WildFly Core 1.0.2.Final) started (with errors) in 4043ms - Started 360 of 557 services (26 services failed or missing dependencies, 242 services are lazy, passive or on-demand)
09:05:11,616 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) WFLYWELD0010: Stopping weld service for deployment JMSProject.war
09:05:11,656 INFO [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0028: Stopped deployment JMSProject.war (runtime-name: JMSProject.war) in 46ms
09:05:11,700 INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0009: Undeployed "JMSProject.war" (runtime-name: "JMSProject.war")
09:05:11,705 INFO [org.jboss.as.controller] (DeploymentScanner-threads - 1) WFLYCTL0183: Service status report
WFLYCTL0184: New missing/unsatisfied dependencies:
service jboss.deployment.unit."JMSProject.war".WeldBootstrapService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".WeldInstantiator, service jboss.deployment.unit."JMSProject.war".component.JmsSender.WeldInstantiator, service jboss.deployment.unit."JMSProject.war".component.JmsSender.WeldInterceptorBindingsService, service jboss.deployment.unit."JMSProject.war".WeldStartService, WFLYCTL0208: ... and 7 more ]
service jboss.deployment.unit."JMSProject.war".WeldStartService (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".WeldInstantiator, service jboss.deployment.unit."JMSProject.war".component.JmsSender.WeldInstantiator, service jboss.deployment.unit."JMSProject.war".component."com.sun.faces.config.ConfigureListener".WeldInstantiator, WFLYCTL0208: ... and 9 more ]
service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.CREATE (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.START]
service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService, service jboss.deployment.unit."JMSProject.war".moduleDeploymentRuntimeInformationStart]
service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.VIEW."abc.jms.JmsReceiver".MESSAGE_ENDPOINT (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.START]
service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.WeldInstantiator (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.START]
service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.WeldInterceptorBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.WeldInstantiator]
service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.ejb.non-functional-timerservice (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.START]
service jboss.deployment.unit."JMSProject.war".component.JmsSender.CREATE (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsSender.START]
service jboss.deployment.unit."JMSProject.war".component.JmsSender.JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component.JmsSender.START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.deployment.unit."JMSProject.war".component.JmsSender.VIEW."abc.jms.JmsSender".LOCAL (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsSender.START]
service jboss.deployment.unit."JMSProject.war".component.JmsSender.WeldInstantiator (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsSender.START]
service jboss.deployment.unit."JMSProject.war".component.JmsSender.WeldInterceptorBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsSender.WeldInstantiator]
service jboss.deployment.unit."JMSProject.war".component.JmsSender.ejb.non-functional-timerservice (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component.JmsSender.START]
service jboss.deployment.unit."JMSProject.war".component."com.sun.faces.config.ConfigureListener".CREATE (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."com.sun.faces.config.ConfigureListener".START]
service jboss.deployment.unit."JMSProject.war".component."com.sun.faces.config.ConfigureListener".JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component."com.sun.faces.config.ConfigureListener".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.deployment.unit."JMSProject.war".component."javax.faces.webapp.FacetTag".CREATE (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."javax.faces.webapp.FacetTag".START]
service jboss.deployment.unit."JMSProject.war".component."javax.faces.webapp.FacetTag".JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component."javax.faces.webapp.FacetTag".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.deployment.unit."JMSProject.war".component."javax.faces.webapp.FacetTag".WeldInstantiator (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."javax.faces.webapp.FacetTag".START]
service jboss.deployment.unit."JMSProject.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component."javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.deployment.unit."JMSProject.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component."javax.servlet.jsp.jstl.tlv.ScriptFreeTLV".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldInitialListener".CREATE (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldInitialListener".START]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldInitialListener".JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldInitialListener".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldInitialListener".WeldInstantiator (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldInitialListener".START]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".CREATE (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".START]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".JndiBindingsService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".START (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject, service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".WeldInstantiator (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".START]
service jboss.deployment.unit."JMSProject.war".jndiDependencyService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldTerminalListener".START, service jboss.deployment.unit."JMSProject.war".component."org.jboss.weld.servlet.WeldInitialListener".START, service jboss.deployment.unit."JMSProject.war".WeldStartService, service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.START, WFLYCTL0208: ... and 3 more ]
service jboss.deployment.unit."JMSProject.war".moduleDeploymentRuntimeInformation (missing) dependents: [service jboss.deployment.unit."JMSProject.war".moduleDeploymentRuntimeInformationStart, service jboss.deployment.unit."JMSProject.war".component.JmsReceiver.START, service jboss.deployment.unit."JMSProject.war".component.JmsSender.START]
service jboss.naming.context.java.app.JMSProject.env (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.BeanManager (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.DefaultContextService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.DefaultDataSource (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.DefaultJMSConnectionFactory (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.DefaultManagedExecutorService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.DefaultManagedScheduledExecutorService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.DefaultManagedThreadFactory (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.EJBContext (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.TimerService (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.TransactionSynchronizationRegistry (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.UserTransaction (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.env (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService]
service jboss.naming.context.java.module.JMSProject.JMSProject.env."abc.jms.JmsSender".connectionFactory (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService, service jboss.deployment.unit."JMSProject.war".component.JmsSender.START]
service jboss.naming.context.java.module.JMSProject.JMSProject.env."abc.jms.JmsSender".queue (missing) dependents: [service jboss.deployment.unit."JMSProject.war".jndiDependencyService, service jboss.deployment.unit."JMSProject.war".component.JmsSender.START]
service jboss.server.global-request-controller.control-point."JMSProject.war".undertow (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService]
service jboss.undertow.deployment.default-server.default-host./JMSProject (missing) dependents: [service jboss.deployment.unit."JMSProject.war".deploymentCompleteService]
service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject]
service jboss.undertow.deployment.default-server.default-host./JMSProject.codec (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService]
service jboss.undertow.deployment.default-server.default-host./JMSProject.session (missing) dependents: [service jboss.undertow.deployment.default-server.default-host./JMSProject.UndertowDeploymentInfoService]
09:05:16,479 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found JMSProject.war in deployment directory. To trigger deployment create a file called JMSProject.war.dodeploy
09:15:08,434 INFO [org.jboss.as.repository] (ServerService Thread Pool -- 71) WFLYDR0009: Content /Users/cwi/java/wildfly-9.0.2.Final/standalone/data/content/08/0c5a481cd7abf27bfd4b48edf73b1cb214085e is obsolete and will be removed
09:15:08,443 INFO [org.jboss.as.repository] (ServerService Thread Pool -- 71) WFLYDR0002: Content removed from location /Users/cwi/java/wildfly-9.0.2.Final/standalone/data/content/08/0c5a481cd7abf27bfd4b48edf73b1cb214085e/content
如果我将mappedName更改为远程JNDI名称,它就会起作用
@Stateless
public class JmsSender implements Serializable {
@Resource(mappedName="java:jboss/exported/jms/queue/TestQueue")
private Queue queue;
或者我将无状态EJB切换到一个依赖的CDI Bean
@Dependent
public class JmsSender implements Serializable {
@Resource(mappedName="queue/TestQueue")
private Queue queue;
Wildfly配置如下所示:
<subsystem xmlns="urn:jboss:domain:messaging:3.0">
<hornetq-server>
<security-enabled>false</security-enabled>
<journal-file-size>102400</journal-file-size>
<connectors>
<http-connector name="http-connector" socket-binding="http">
<param key="http-upgrade-endpoint" value="http-acceptor"/>
</http-connector>
<http-connector name="http-connector-throughput" socket-binding="http">
<param key="http-upgrade-endpoint" value="http-acceptor-throughput"/>
<param key="batch-delay" value="50"/>
</http-connector>
<in-vm-connector name="in-vm" server-id="0"/>
</connectors>
<acceptors>
<http-acceptor http-listener="default" name="http-acceptor"/>
<http-acceptor http-listener="default" name="http-acceptor-throughput">
<param key="batch-delay" value="50"/>
<param key="direct-deliver" value="false"/>
</http-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
</acceptors>
<security-settings>
<security-setting match="#">
<permission type="send" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
</security-setting>
</security-settings>
<address-settings>
<address-setting match="#">
<dead-letter-address>jms.queue.DLQ</dead-letter-address>
<expiry-address>jms.queue.ExpiryQueue</expiry-address>
<max-size-bytes>10485760</max-size-bytes>
<page-size-bytes>2097152</page-size-bytes>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
</address-setting>
</address-settings>
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="http-connector"/>
</connectors>
<entries>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
<entry name="java:jboss/DefaultJMSConnectionFactory"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="ExpiryQueue">
<entry name="java:/jms/queue/ExpiryQueue"/>
</jms-queue>
<jms-queue name="DLQ">
<entry name="java:/jms/queue/DLQ"/>
</jms-queue>
<jms-queue name="TestQueue">
<entry name="queue/TestQueue"/>
<entry name="java:jboss/exported/jms/queue/TestQueue"/>
</jms-queue>
<jms-topic name="TestTopic">
<entry name="topic/TestTopic"/>
<entry name="java:jboss/exported/jms/topic/TestTopic"/>
</jms-topic>
</jms-destinations>
</hornetq-server>
</subsystem>
那么,为什么不能将JMS队列注入到无状态EJB中,为什么它可以在CDI bean中工作呢?我做错了什么?
提前谢谢!
克里斯
我认为这应该行得通:
@Resource(mappedName="java:/queue/TestQueue")
private Queue queue;
另请参阅https://docs.jboss.org/author/display/wfly9/jndi+引用
问题内容: 我在下面有这样的设置。这是一个简化的版本,但我认为它已涵盖了基本思想。我正在使用Jersey 2.16,Java 1.8和Glassfish Open Source 4.1 但是,当我部署并尝试访问Web服务时,我从安全上下文中得到了NullPointer异常。似乎根本没有注入上下文。我检查了这是secContext变量本身,而不仅仅是从getUserPrincipal()返回的nul
场景:EjbA和EjbB都是远程无状态会话bean。 对b的这些方法调用中的任何一个都可以发生在集群环境中的不同节点/VM上,这是否正确? 甚至连对method1的调用? 我的意思是,如果一些客户端调用方法foo,是否会发生这样的情况:在这个事务中,在node1上调用方法1,下一个对方法1的调用,在同样的foo()调用期间,转到node2上的Ejb实例? 解释下面引用的"Enterprise Ja
在EJB3.1中,在无状态EJB中有一个同步块可以吗? 同步块用于在出现连接错误时更新连接。
我试图将一些消息从JMS代码放到本地队列管理器中定义的本地队列中。我在WebSphere MQ中定义了一个本地队列,并使用JMS代码放置消息。我在这里做得对吗。我没有看到WebSphere队列中的消息。 以下是代码:
我不理解无状态会话bean。文档说,instances变量可能包含特定于客户机的状态,然后说,当方法完成时,不应该保留状态。
我有一个EJB无状态会话Bean。我有以下要求: 这个无状态EJB应该在启动时初始化 初始化代码应该对数据库进行事务性访问 问题是: @Startup仅适用于@Singleton EJB @PostConstruct注释(至少在WebSphere上)在这一点上没有事务性上下文,所以初始化代码在这里爆炸! 可能的解决方案? 使用JavaEE定时器,但它似乎是为周期性执行而设计的。我只想在零点执行一次