Problem with resource injection in ejb3 jboss 5.0.1
etantonio May 27, 2014 6:53 AMGood morning,
i'm working on this problem for some days so I decide to ask you an help.
I've a simple ejb that needs to inject a message in a queue, I'm using ant to build the project and I want the real name of the queue it is just in ant and not in java code,
so I used ejb-jar.xml and jboss.xml to define the queue and connectionFactory, these are attached to this post.
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>
<session>
<ejb-name>HubMessageManagerSessionBean</ejb-name>
<mapped-name>HubMessageManagerSessionBeanMappedName</mapped-name>
<business-local>it.trs.mcf.hubmessage.hubmessagemanager.HubMessageManagerSessionBeanLocal</business-local>
<business-remote>it.trs.mcf.hubmessage.hubmessagemanager.HubMessageManagerSessionBeanRemote</business-remote>
<ejb-class>it.trs.mcf.hubmessage.hubmessagemanager.HubMessageManagerSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>MyHubQueueFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Application</res-auth>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>MyHubQueue</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
</session>
</enterprise-beans>
</ejb-jar>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<?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>
<session>
<ejb-name>HubMessageManagerSessionBean</ejb-name>
<jndi-name>it.trs.mcf.hubmessage.hubmessagemanager.HubMessageManagerSessionBean</jndi-name>
<resource-ref>
<res-ref-name>MyHubQueueFactory</res-ref-name>
<jndi-name>ConnectionFactory</jndi-name>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>MyHubQueue</resource-env-ref-name>
<jndi-name>queue/hubMessageQ</jndi-name>
</resource-env-ref>
</session>
</enterprise-beans>
</jboss>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
the ejb is simply the following:
package it.trs.mcf.hubmessage.hubmessagemanager;
...
@Stateless(mappedName = "HubMessageManagerSessionBeanMappedName")
public class HubMessageManagerSessionBean implements HubMessageManagerSessionBeanRemote, HubMessageManagerSessionBeanLocal {
@Resource(mappedName = "MyHubQueueFactory")
private QueueConnectionFactory queueConnFactory;
@Resource(mappedName = "MyHubQueue")
private Queue queue;
private QueueConnection queueConnection;
private QueueSession queueSession;
private QueueSender queueSender;
public HubMessageManagerSessionBean() {
System.out.println("HubMessageManagerSessionBean.HubMessageManagerSessionBean() INIZIO");
}
@PostConstruct
public void init() {
System.out.println("HubMessageManagerSessionBean.init() INIZIO");
try {
Context initCtx = new InitialContext();
Context myEnv = (Context) initCtx.lookup("java:comp/env");
queue = (Queue)myEnv.lookup("MyHubQueue");
System.out.println("myEnv queue: " + queue.getClass() + " " + queue.toString());
queueConnFactory = (QueueConnectionFactory)myEnv.lookup("MyHubQueueFactory");
System.out.println("myEnv queueConnFactory: " + queueConnFactory.getClass() + " " + queueConnFactory.toString());
queueConnection = queueConnFactory.createQueueConnection();
System.out.println("queueConnection: " + queueConnection.getClass() + " " + queueConnection.toString());
queueSession = queueConnection.createQueueSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
System.out.println("queueSession: " + queueSession.getClass() + " " + queueSession.toString());
..
queueSender = queueSession.createSender(queue);
System.out.println("queueSender: " + queueSender.getClass() + " " + queueSender.toString());
} catch (Throwable e) {
System.out.println("ECCEZIONE: " + e.getMessage());
e.printStackTrace();
} finally{
System.out.println("HubMessageManagerSessionBean.init() FINE");
}
}
.}
I've packaged this ejb in a simple ear, the result is that when I call the ejb I've the following error: