我希望在jboss7和ActiveMQ下部署两个相同的MDB实例,以处理来自两个不同队列的消息。因此,这是我的ejb-jar.xml的一部分:
<message-driven>
<ejb-name>FirstInstanceOfMyMDB</ejb-name>
<ejb-class>de.xx.xx.MyMDB</ejb-class>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>activemq/queue/queue_1</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
<message-driven>
<ejb-name>SecondInstanceOfMyMDB</ejb-name>
<ejb-class>de.xx.xx.MyMDB</ejb-class>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>activemq/queue/queue_2</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
这个配置可以正常工作。
现在我想为每个实例添加一些特定的属性:System = A
用于 FirstInstanceOfMyMDB,System = B
用于 SecondInstanceOfMyMDB。
我已经尝试使用 <env-entry>
在 <message-driven>
中注入带有 @Resource
注释的 System
:
<message-driven>
<ejb-name>FirstInstanceOfMyMDB</ejb-name>
...
<env-entry>
<env-entry-name>System</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>A</env-entry-value>
</env-entry>
</message-driven>
<message-driven>
<ejb-name>SecondInstanceOfMyMDB</ejb-name>
...
<env-entry>
<env-entry-name>System</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>B</env-entry-value>
</env-entry>
</message-driven>
但是,JBoss似乎只将System
设置为A或B。可能是因为同一命名空间用于设置System
。
所以我的问题是:设置自定义实例MDB(EJB)属性的最佳实践是什么?
使用用户1181247建议的方法:
@Resource(name="System")
private String System;
我可以在ejbmodule中使用ejb-jar.xml将我的MDBs部署到METH-INF目录中,并且它们可以按预期工作。 尝试将相同的类与相同的ejb-jar.xml部署在war文件中,放置在WEB-INF文件夹中时,我遇到了以下异常:
[0m[31m09:13:56,823 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC000001: Failed to start service jboss.deployment.unit."Server.war".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.unit."Server.war".INSTALL: JBAS018733: Failed to process phase INSTALL of deployment "Server.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-8.0.0.Alpha1-SNAPSHOT.jar:8.0.0.Alpha1-SNAPSHOT]
...
Caused by: java.lang.IllegalArgumentException: JBAS011053: Incompatible conflicting binding at java:comp/env/System source: org.jboss.as.ee.component.EnvEntryInjectionSource@1291e
如果 env-entry-value 对于两个实例来说是相同的,则可以无异常地部署!您是否需要为war文件进行另外/附加的配置?