部署应用程序时收到以下错误:
/opt/eap/bin # cat ../standalone/deployments/SitioWebFinal.war.failed { "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.jboss.java:env.jms.fabrica"],"WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.SitioWebFinal.SitioWebFinal.env.jms.fabrica is missing [jboss.naming.context.java.jboss.java:env.jms.fabrica]"]
我有以下代码将消息发送到amq服务器:
package amqlib;
import javax.naming.*;
import javax.jms.*;
public class Producctor {
public void enviaMensajeCola(String mundo) throws JMSException {
try {
InitialContext initCtx = new InitialContext();
QueueConnectionFactory f = (QueueConnectionFactory) initCtx.lookup("java:jboss/exported/jms/fabrica");
QueueConnection con = f.createQueueConnection();
con.start();
QueueSession ses = con.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
InitialContext initCtx2 = new InitialContext();
Queue t = (Queue) initCtx2.lookup("/queue");
QueueSender sender = ses.createSender(t);
TextMessage msg = ses.createTextMessage();
InputStreamReader(System.in));
String s = mundo;
msg.setText(s);
// 7) send message
sender.send(msg);
System.out.println("Message successfully sent.");
// 8) connection close
con.close();
}
catch (Exception e) {
System.out.println("Este es el error " + e);
}
}
public static void main(String[] args) throws JMSException {
Producctor p = new Producctor();
p.enviaMensajeCola("Hola Mundo");
}
}
这是standalone-full-ha.xml
配置文件中的连接工厂的名称。
<connection-factory name="fabrica" entries="java:jboss/exported/jms/fabrica" connectors="in-vm"/>
这是.war内的web.xml,这与我在tomcat 9中使用的xml是相同的。如果它不是seme文件,我就不知道。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>SitioWebFinal</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<distributable/>
<resource-ref>
<description>ConnectionFactory</description>
<res-ref-name>jms/fabrica</res-ref-name>
<res-type>org.apache.activemq.activeMQConnectionFactory</res-type>
<res-auth>Container</res-auth>
<lookup-name>java:env/jms/fabrica</lookup-name>
</resource-ref>
</web-app>
我也有context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context name="/SitioWebFinal" antiJARLocking="true">
<Resource
name="jms/fabrica"
auth="Container"
type="org.apache.activemq.activeMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL="tcp://amq-cicd-int-amq-tcp.svc.cluster.local:61616"
brokerName="activeMQBroker"
useEmbeddedBroker="false"/>
<Resource name="jms/topic"
auth="Container"
type="org.apache.activemq.command.activeMQTopic"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="APP.JMS.TOPIC"/>
<Resource name="jms/queue"
auth="Container"
type="org.apache.activemq.command.activeMqqueue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="APP.JMS.QUEUE"/>
</Context>
致谢