我正在尝试将WAR部署到我的JBoss服务器,而WAR依赖于EJB模块。当我尝试部署WAR时,出现以下错误:
Failed to start service jboss.deployment.unit Caused by: java.lang.RuntimeException: javax.resource.spi.InvalidPropertyException: Destination is mandatory
我的ejb-jar有:
<message-driven>
<ejb-name>LeagueListenerMDB</ejb-name>
<ejb-class>com.club.ejb.LeagueListenerMDB</ejb-class>
<transaction-type>Container</transaction-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Topic</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>java:/topic/ejava/projects/contests</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
我的EJB注释为:
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/topic/ejava/projects/contests"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "ContestAction = 'ContestScheduled' OR "
+ "ContestAction = 'ContestRescheduled' OR "
+ "ContestAction = 'ContestCanceled'"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
})
我在注释和ejb-jar中有目的地,所以我不确定问题是什么。
答案 0 :(得分:1)
添加
@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),
我从来没有使用过MDB目的地的java:前缀,所以这可能会让它运行起来:
@ActivationConfigProperty(propertyName = "destination",
propertyValue = "topic/ejava/projects/contests"),
答案 1 :(得分:0)
我知道了,在将MDB重命名为另一个名称(为了避免重复的jndi条目具有相同的名称&#34; testQueue&#34;)并修改ejb-jar.xml之后,它可以工作:
package test;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSDestinationDefinition;
import javax.jms.Message;
import javax.jms.MessageListener;
@JMSDestinationDefinition(name = "NewMessageBean", interfaceName = "javax.jms.Queue", resourceAdapter = "jmsra", destinationName = "testQueue")
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "willBeOverwrittenInDeploymentDescriptor")
})
public class NewMessageBean implements MessageListener {
public NewMessageBean() {
}
@Override
public void onMessage(Message message) {
}
}
仍然需要ActivationConfigProperty目标,否则在部署阶段会抛出异常。
目标值被以下ejb-jar.xml
覆盖<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">
<enterprise-beans>
<message-driven>
<ejb-name>NewMessageBean</ejb-name>
<ejb-class>test.NewMessageBean</ejb-class>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>/jms/testClientQueue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</ejb-jar>
使用此ejb-jar.xml,mdb连接到/ jms / testClientQueue