混合注释和部署描述符时“目标是必需的”

时间:2015-01-19 16:52:46

标签: wildfly-8

我正在尝试在wildfly 8.2.0-Final上定义带有注释和部署描述符的消息驱动bean。我想用注释声明配置的静态部分,使用xml部署描述符声明可变部分。部署以下mdb时,我遇到了异常。

这是.failed-File:

的内容
  

{“JBAS014671:服务失败”=> {“jboss.deployment.unit。\”MdbWithAnnotationsAndDescritors.jar \“。component.NewMessageBean.START”=> “服务jboss.deployment.unit中的org.jboss.msc.service.StartException。”MdbWithAnnotationsAndDescritors.jar \“。component.NewMessageBean.START:java.lang.RuntimeException:javax.resource.spi.InvalidPropertyException:Destination is mandatory       引起:java.lang.RuntimeException:javax.resource.spi.InvalidPropertyException:目标是必需的       引起:javax.resource.spi.InvalidPropertyException:目的地是强制性的“}}

mdb是

package test;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSDestinationDefinition;
import javax.jms.Message;
import javax.jms.MessageListener;
@JMSDestinationDefinition(name = "testQueue", interfaceName = "javax.jms.Queue", resourceAdapter = "jmsra", destinationName = "testQueue")
@MessageDriven(activationConfig = {
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class NewMessageBean implements MessageListener {
    public NewMessageBean() {
    }
    @Override
    public void onMessage(Message message) {
    }
}

和jboss.xml部署描述符:

<jboss xsi:schemaLocation="http://java.sun.com/xml/ns/javaee                             http://www.jboss.org/j2ee/schema/jboss_5_0.xsd" version="3.0">
    <security-domain>tutorial-default</security-domain>
    <enterprise-beans>
        <message-driven>
            <ejb-name>testQueue</ejb-name>
            <destination-jndi-name>testQueue</destination-jndi-name>
        </message-driven>    
    </enterprise-beans>
</jboss>

ejb-jar.xml为空:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        version="3.2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/ejb-jar_3_2.xsd">

</ejb-jar>

2 个答案:

答案 0 :(得分:2)

知道了,我将目标ActivationConfigProperty添加到mdb类中以消除异常:

package test;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSDestinationDefinition;
import javax.jms.Message;
import javax.jms.MessageListener;

/**
 *
 * @author rainer
 */
@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) {
    }

}

我删除了JMSDestinationDefinition,因为它不需要,我使用管理控制台创建了队列。 要覆盖目标jndi名称,我创建了以下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>

现在部署mdb并侦听队列jms / testClientQueue

答案 1 :(得分:0)

您需要在ejb-jar.xml中定义而不是jboss.xml

您可能更喜欢使用注释替换,其中值是从系统属性中提取的,或者是在较新版本的wildfly或EAP 6.4中的jboss.properties中提取的