简体   繁体   English

将消息驱动的Bean部署到JBoss服务器

[英]Deploying a Message Driven Bean to JBoss Server

I am trying to deploy a WAR to my JBoss Server, and the WAR has a dependency on an EJB module. 我正在尝试将WAR部署到我的JBoss Server中,并且WAR对EJB模块具有依赖性。 When I try to deploy the WAR I get the following error: 当我尝试部署WAR时,出现以下错误:

Failed to start service jboss.deployment.unit Caused by: java.lang.RuntimeException: javax.resource.spi.InvalidPropertyException: Destination is mandatory

My ejb-jar has: 我的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>

My EJB is annotated with: 我的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")

}) })

I have the destination in the annotation and the ejb-jar, so I'm not sure what the problem is. 我在批注和ejb-jar中有目的地,所以我不确定是什么问题。

Add

@ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),

and I haven't ever used java: prefix with MDB destination, so this might get it working as well: 而且我从未使用java:前缀和MDB目标,因此这也可以使其正常工作:

@ActivationConfigProperty(propertyName = "destination",
    propertyValue = "topic/ejava/projects/contests"),

I got it, after renaming the MDB to another name (to avoid duplicate jndi entries with the same Name "testQueue") and modifying the ejb-jar.xml, it works: 我得到了它,将MDB重命名为另一个名称(以避免重复的具有相同名称“ testQueue”的jndi条目)并修改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) {
    }

}

The ActivationConfigProperty destination is still needed, otherwise an exception gets thrown in the deployment phase. 仍然需要ActivationConfigProperty目标,否则在部署阶段会引发异常。

The destination-value gets overwritten by the following ejb-jar.xml 目标值被以下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>

With this ejb-jar.xml, the mdb connects to /jms/testClientQueue 通过此ejb-jar.xml,mdb连接到/ jms / testClientQueue

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM