I developed a resource adapter that I would like to use within my application ear, deployed in JBoss 5.1. After playing around with annotations and xml files, I came up with the following setup.
ejb-jar.xml
<ejb-jar 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_0.xsd" version="3.0">
<enterprise-beans>
<message-driven>
<display-name>MyUpdateService</display-name>
<ejb-name>MyUpdateService</ejb-name>
<ejb-class>com.my.package.MyUpdateService</ejb-class>
<messaging-type>com.my.other.package.AdapterListener</messaging-type>
<transaction-type>Bean</transaction-type>
</message-driven>
</enterprise-beans>
</ejb-jar>
jboss.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE jboss PUBLIC
"-//JBoss//DTD JBOSS 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">
<jboss>
<enterprise-beans>
<message-driven>
<ejb-name>MyUpdateService</ejb-name>
<activation-config>
<activation-config-property>
<activation-config-property-name>parameter1</activation-config-property-name>
<activation-config-property-value>value1</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>parameter2</activation-config-property-name>
<activation-config-property-value>value2</activation-config-property-value>
</activation-config-property>
</activation-config>
<resource-adapter-name>myear.ear#adaptor.rar</resource-adapter-name>
<depends>jboss.jca:service=RARDeployment,name='myear.ear#adaptor.rar'</depends>
</message-driven>
</enterprise-beans>
</jboss>
MyUpdateService
#TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class EuronextUpdateService implements MulticastListener, MessageDrivenBean {
[snip]
}
I also tried most combinations of annotations as opposed to xml files, however, I always get the same result:
All beans are deployed fine, also the MyUpdateService bean. The resource adapter does send messages to my bean, which can process it just fine.
While I can work with the adapter like this, I do get the following exception in my log, which I really would like to get rid of:
2011-02-23 11:15:54,640 WARN [org.jboss.resource.adapter.jms.inflow.JmsActivation] (WorkManager(2)-75) Failure in jms activation org.jboss.resource.adapter.jms.inflow.JmsActivationSpec#26af5ca9(ra=org.jboss.resource.adapter.jms.JmsResourceAdapter#157024fc destination=/topic/MyTopic destinationType=javax.jms.Topic tx=false ack=Auto-acknowledge durable=false reconnect=10 provider=java:/DefaultJMSProvider user=null maxMessages=1 minSession=1 maxSession=1 keepAlive=60000 useDLQ=true DLQHandler=org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler DLQJndiName=queue/DLQ DLQUser=null DLQMaxResent=0)
javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.IllegalStateException: BaseClassLoader#26780d3c{vfszip:/opt/jboss-5.1.0.GA/server/default/deploy/myear.ear/} classLoader is not connected to a domain (probably undeployed?) for class org.jnp.interfaces.NamingContextFactory]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:175)
at org.jboss.util.naming.Util.lookup(Util.java:179)
at org.jboss.resource.adapter.jms.inflow.JmsActivation.setupJMSProviderAdapter(JmsActivation.java:397)
at org.jboss.resource.adapter.jms.inflow.JmsActivation.setup(JmsActivation.java:346)
at org.jboss.resource.adapter.jms.inflow.JmsActivation$SetupActivation.run(JmsActivation.java:729)
at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:205)
at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:260)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalStateException: BaseClassLoader#26780d3c{vfszip:/opt/jboss-5.1.0.GA/server/default/deploy/myear.ear/} classLoader is not connected to a domain (probably undeployed?) for class org.jnp.interfaces.NamingContextFactory
at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:793)
at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:441)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
... 12 more
Any ideas?
Cheers,
Che
Related
I have two web REST applications that I would like to deploy using the same path:
http://server:8080/commonpath/applicationA
http://server:8080/commonpath/applicationB
In both webapps I have configured web.xml under WEB-INF:
<web-app 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/web-app_3_0.xsd"
version="3.0">
<module-name>commonpath</module-name>
</web-app>
I have also tried the same using jboss-web.xml:
<jboss-web>
<context-root>commonpath</context-root>
</jboss-web>
Nothing seems to work however and I see the following exception:
{"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"applicationB.war\".POST_MODULE" => "WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"applicationB.war\"
14:16:34 Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.naming.context.java.module.distribution.distribution.ValidatorFactory is already registered"}}}}
If I use two different module-names they deploy without problem. My server is Wildfly 23.0.2
I'm using JBoss EAP 7.1.6 (with weld-api-2.4.0.SP1-redhat-1.jar). My web application (war) embeds a "common" library which contains an alternative bean, like this:
#Alternative
#ApplicationScoped
public class EntityManagerProvider {
#PersistenceUnit
private EntityManagerFactory entityManagerFactory;
My web application doesn't use this alternative bean. In this case, I don't have any persistence mechanism.
When I deploy the webapp (with a dependency to the third-party library), I receive the following stacktrace:
15:01:08,196 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.deployment.unit."sample-monitoring.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."sample-monitoring.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1978)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException: WFLYWELD0037: Error injecting persistence unit into CDI managed bean. Can't find a persistence unit named « » in deployment sample-monitoring.war for injection point private javax.persistence.EntityManager org.sample.EntityManagerProvider.entityManagerFactory
at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.getScopedPUName(WeldJpaInjectionServices.java:114)
at org.jboss.as.weld.services.bootstrap.WeldJpaInjectionServices.registerPersistenceContextInjectionPoint(WeldJpaInjectionServices.java:77)
at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:350)
at org.jboss.weld.injection.ResourceInjectionFactory$PersistenceContextResourceInjectionProcessor.getResourceReferenceFactory(ResourceInjectionFactory.java:338)
at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createFieldResourceInjection(ResourceInjectionFactory.java:216)
at org.jboss.weld.injection.ResourceInjectionFactory$ResourceInjectionProcessor.createResourceInjections(ResourceInjectionFactory.java:188)
at org.jboss.weld.injection.ResourceInjectionFactory.discoverType(ResourceInjectionFactory.java:448)
at org.jboss.weld.injection.ResourceInjectionFactory.getResourceInjections(ResourceInjectionFactory.java:96)
at org.jboss.weld.injection.producer.ResourceInjector.<init>(ResourceInjector.java:59)
at org.jboss.weld.injection.producer.ResourceInjector.of(ResourceInjector.java:49)
at org.jboss.weld.injection.producer.BeanInjectionTarget.<init>(BeanInjectionTarget.java:63)
at org.jboss.weld.injection.producer.BeanInjectionTarget.createDefault(BeanInjectionTarget.java:47)
at org.jboss.weld.manager.InjectionTargetFactoryImpl.chooseInjectionTarget(InjectionTargetFactoryImpl.java:113)
at org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:86)
at org.jboss.weld.bean.ManagedBean.<init>(ManagedBean.java:100)
at org.jboss.weld.bean.ManagedBean.of(ManagedBean.java:80)
at org.jboss.weld.bootstrap.AbstractBeanDeployer.createManagedBean(AbstractBeanDeployer.java:274)
at org.jboss.weld.bootstrap.BeanDeployer.createClassBean(BeanDeployer.java:226)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:74)
at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$2.doWork(ConcurrentBeanDeployer.java:71)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
I try to explicit exclude the scan of the the persistence class in the beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
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/beans_1_1.xsd"
bean-discovery-mode="all" version="1.2">
<scan>
<exclude name="com.other.library.dao.util.EntityManagerProvider" />
<exclude name="com.other.library.dao.util.**" />
</scan>
</beans>
But I still receive the same error :-(
What am I doing wrong? Thanks in advance.
I am trying to create a web service in a web application on netbeans 8.2 (server-tomcat 8.0.27.0) which can connect to a database on postgres and read a table named "test". i have this code in download.java (web service in a package called serve)
Download.java
#WebService(serviceName = "download")
public class Download {
Connection con=null;
private DataSource getJdbcPostgres() throws NamingException, SQLException {
Context c = new InitialContext();
DataSource ds=(DataSource) c.lookup("java:comp/env/jdbc/postgres");
con=ds.getConnection();
return ds;
}
#WebMethod(operationName = "download")
public String download(#WebParam(name = "username")String username, #WebParam(name = "id")String id) throws ClassNotFoundException, SQLException {
String sql = "select * from test where id="+id;
Class.forName("org.postgresql.Driver");
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();
ResultSetMetaData rsmd=rs.getMetaData();
rs.next();
return "";
}
}
here's my context.xml file (in META-INF)
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/service2">
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/postgres"
username="someusername" password="somepassword" maxTotal="20" maxIdle="10"
maxWaitMillis="-1"/>
</Context>
and here's web.xml (in WEB-INF):
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
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/web-app_3_1.xsd">
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>download</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>download</servlet-name>
<url-pattern>/download</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<resource-ref>
<description>postgreSQL Datasource example</description>
<res-ref-name>jdbc/postgres</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
clean and build command is successful but it doesn't deploy on apache tomcat server
error message (output when I tried to deploy it):
Checking data source definitions for missing JDBC drivers...
Undeploying ...
undeploy?path=/service2
OK - Undeployed application at context path /service2
In-place deployment at D:\NetBeansProjects\service2\build\web
Deployment is in progress...
deploy?config=file%3A%2FC%3A%2FUsers%2FTRAINE%7E3%2FAppData%2FLocal%2FTemp%2Fcontext1366288511044657094.xml&path=/service2
FAIL - Deployed application at context path /service2 but context failed to start
D:\NetBeansProjects\service2\nbproject\build-impl.xml:1094: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 2 seconds)
when i tried to change server to GlassFish 4.1.1, it says:
Severe: WSSERVLET11: failed to parse runtime descriptor:
com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator
serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
Caused by: com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator
serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
Severe: Exception while loading the app
Severe: Undeployment failed for context /service2
Severe: Exception while loading the app : java.lang.IllegalStateException:
ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
org.apache.catalina.LifecycleException: javax.servlet.ServletException:
com.sun.xml.ws.transport.http.servlet.WSServletException: WSSERVLET11: failed to
parse runtime descriptor: com.sun.xml.ws.spi.db.DatabindingException:
com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of
IllegalAnnotationExceptions
javax.xml.transform.SourceLocator is an interface, and JAXB can't handle
interfaces.
this problem is related to the following location:
at javax.xml.transform.SourceLocator
at public javax.xml.transform.SourceLocator serve.jaxws.TransformerConfigurationExceptionBean.locator
at serve.jaxws.TransformerConfigurationExceptionBean
I am a newcomer to this field so plz help me if im wrong somewhere or missing something!
I don't know why it happened but I just put try-catch instead of throws and it is getting deployed!
#WebMethod(operationName = "download")
public String download(#WebParam(name = "username")String username, #WebParam(name = "id")String id) {
try {
String sql="select * from test";
Connection conn=myDatasource.getConnection();
PreparedStatement pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
}
catch (SQLException ex) {
Logger.getLogger(connect.class.getName()).log(Level.SEVERE, null, ex);
}
return "someString";
}
Can anyone suggest why didn't it work earlier? Although my problem is solved yet I'm curious to know what was wrong with 'throws Exception'!
P.S. I'm running it on GlassFish 4.1.1 this time
We are getting the below error when we are trying to integrate Wso2 4.8.1 with Spring batch 3.0.3 using spring mediator. The spring batch jar used has the xsd referred in the XML file. Both the mediator class jar and the spring batch jar are in the path wso2esb-4.8.1\repository\components\lib.
Error
2016-02-17 11:26:35,166 [-] [localhost-startStop-1] ERROR SynapseConfiguration Error in initializing Proxy Service [ SampleProxy1] Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: resource loaded through InputStream
2016-02-17 11:27:09,430 [-] [PassThroughMessageProcessor-1] ERROR NativeWorkerPool Uncaught exception
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
Offending resource: resource loaded through InputStream
at
org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:318)
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1435)
org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1428)
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:185)
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
org.apache.synapse.mediators.spring.SpringMediator.buildAppContext(SpringMediator.java:132)
org.apache.synapse.mediators.spring.SpringMediator.mediate(SpringMediator.java:81)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:77)
org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:47)
org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:131)
org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:166)
org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:411)
org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:183)
org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
java.lang.Thread.run(Thread.java:682)
and
2016-02-17 11:28:10,272 [-] [HTTP-Listener I/O dispatcher-1] WARN SourceHandler Connection time out after request is read: http-incoming-1
2016-02-17 11:39:25,506 [-] [Start Level Event Dispatcher] WARN ValidationResultPrinter
The default keystore (wso2carbon.jks) is currently being used. To maximize security when deploying to a production environment, configure a new keystore with a unique password in the production server profile.
XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
I want to deploy two instances of the same MDB to process messages from two different Queues under jboss7 with ActiveMQ. So hier is a part of my 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>
With this configuration everything works well.
Now I want to add some instance-specific propeties to each instance: System = A for FirstInstanceOfMyMDB and System = B for SecondInstanceOfMyMDB.
I have already tried to use within the to get the System injected with #Resource annotation:
<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>
But jboss seems to set System only once either to A or to B. Maybe because the same namespace is used to set the System.
So My Question: What is the best practice to set custom instance MDB (EJB) Proerties?
Using the approch suggested by user1181247:
#Resource(name="System")
private String System;
I can deploy my MDBs within a ejbmodule with ejb-jar.xml in METH-INF directory and thy work as desired.
Tryint to deploy the same classes in a war file with the same ejb-jar.xml in WEB-INF folder I get following exception:
[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
If the env-entry-value is for both instances the same, deploying is done wihout exceptions!
Do I need another/additional configuration for a war file?
I have done pretty much the same injection with my MDBs which worked at one time with AS7 (I'm currently using EAP). The only possible difference I can see between what worked with mine and what you have is I had named my resources. So try this if you haven't already:
#Resource(name = "sysId")
protected String sysId;
More details...I have tested the following on EAP but worked for me on 7.1.1 previously.
My mdb:
public class TestMDB implements MessageListener {
private static final Logger l = Logger.getLogger(TestMDB.class);
#Resource(name="sysId")
private String sysId;
public void onMessage(Message arg0) {
try {
l.info("Received message " + sysId + " - " + ((TextMessage) arg0).getText());
}
catch (JMSException e) {
l.error("Failed to get message", e);
}
}
}
from my ejb-jar
<enterprise-beans>
<message-driven>
<ejb-name>receiver1</ejb-name>
<ejb-class>com.xxxx.test.JMSTest.TestMDB</ejb-class>
<activation-config>
<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-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>queue/xxxin</activation-config-property-value>
</activation-config-property>
</activation-config>
<env-entry>
<env-entry-name>sysId</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>ID1</env-entry-value>
</env-entry>
</message-driven>
<message-driven>
<ejb-name>receiver2</ejb-name>
<ejb-class>com.xxxx.test.JMSTest.TestMDB</ejb-class>
<activation-config>
<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-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value>queue/xxxinit</activation-config-property-value>
</activation-config-property>
</activation-config>
<env-entry>
<env-entry-name>sysId</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>ID2</env-entry-value>
</env-entry>
</message-driven>
</enterprise-beans>
Output:
11:43:20,082 INFO [com.xxxx.test.JMSTest.TestMDB] (Thread-2 (HornetQ-client-global-threads-319126730)) Received message ID1 - hi
11:43:25,088 INFO [com.xxxx.test.JMSTest.TestMDB] (Thread-2 (HornetQ-client-global-threads-319126730)) Received message ID2 - hi2
I noticed this in the EJB spec:
16.2.1 Sharing of Environment Entries
For enterprise beans packaged in an ejb-jar, each enterprise bean defines its own set of environment entries. In this case, all instances of an enterprise bean share the same environment entries; the environment entries are not shared with other enterprise beans.
In a .war, there is only a single naming environment shared between all the components in the module. For enterprise beans packaged in a .war, all enterprise beans share this single naming environment. The enterprise beans share their environment entries with all other enterprise bean components and web components in the .war.
So it seems for some reason that the env-entry approach will work if you deploy an ejb jar but not a war. Maybe split your app up and move to an ear deployment if possible.