我想部署同一個MDB的兩個實例,以使用ActiveMQ處理來自jboss7下兩個不同隊列的消息。所以,票數是我的ejb-jar.xml中的一部分:如何在JBoss 7下定義custome(實例)屬性和MDB(EJB)
<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。
我已經嘗試中的使用,以獲得注入@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)Proerties的最佳實踐是什麼?
使用user1181247提出的計算策略:
@Resource(name="System")
private String System;
我可以根據需要在METH-INF目錄ejb-jar.xml和你的工作的ejbModule內部署我的MDB。 Tryint在與WEB-INF文件夾相同的ejb-jar.xml中的戰爭文件部署相同的類我得到以下異常:
[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: [email protected]
如果將env-entry-值是這兩種情況下是相同的,部署在沒有例外的情況下完成!
我需要另一個/額外配置的戰爭文件?
謝謝你的回答。 – sam
當MDB部署爲jar(ejb-module)時,此方法可用,但如果部署在war文件中,則不會。我完成了我的問題。 – sam
@sam嗯mmmm ...你有沒有試過這個更像7.1.3更穩定的東西? – Marc