JMS producer in session bean on JBoss AS exception 6 exclude

Using JBoss AS 6.1.0 Final with the default deployment profile.

I like to send a JMS message from a Bean session. I installed the following:

/ server / default / deploy / My-hornetq-JMS:

<configuration xmlns="urn:hornetq"
    xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">

    <queue name="queue/DummyMDBean">
        <entry name="jms/DummyMDBean"/>


In the bean, I have:

public class Demo implements DemoRemote, DemoLocal {
    @Resource(mappedName = "java:/ConnectionFactory")
    private static QueueConnectionFactory queueConnectionFactory;

    @Resource(mappedName = "/jms/DummyMDBean")
    private static Queue queue;

    public void example() {
        QueueConnection queueConnection = null;
        try {
            queueConnection = queueConnectionFactory.createQueueConnection();
        } catch (JMSException e) {
            System.out.println("Exception occurred: " + e.toString());

        try {
            QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
            QueueSender queueSender = queueSession.createSender(queue);

            // Send a text message:
            TextMessage textMessage = queueSession.createTextMessage();
            textMessage.setText("Hello World");

        } catch (JMSException e) {
            System.out.println("Exception occurred: " + e.toString());
        } finally {


I am getting the following error:

15:46:05,011 INFO  [STDOUT] Exception occurred: javax.jms.JMSException: Failed to create session factory
15:46:05,661 ERROR [STDERR] javax.jms.JMSException: Failed to create session factory
15:46:05,666 ERROR [STDERR]     at    org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(
15:46:05,667 ERROR [STDERR]     at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(
15:46:05,668 ERROR [STDERR]     at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(
15:46:05,669 ERROR [STDERR]     at com.demo.Demo.example(


15:46:05,782 ERROR [STDERR]     at
15:46:05,783 ERROR [STDERR] Caused by: java.lang.NullPointerException
15:46:05,784 ERROR [STDERR]     at org.hornetq.core.client.impl.ServerLocatorImpl.removeFromConnecting(
15:46:05,784 ERROR [STDERR]     at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(
15:46:05,785 ERROR [STDERR]     at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(
15:46:05,785 ERROR [STDERR]     ... 180 more


line 109 is "queueConnection = queueConnectionFactory.createQueueConnection ();".

I didn't change anything from the default except the xml above. Any ideas about the problem and how to fix it?


source to share

1 answer

Is line 109 in matching the next line?

QueueSender queueSender = queueSession.createSender(queue);


I guess it queue

could be null. You can try to declare your queue like this:

<queue name="queue/DummyMDBean">
    <entry name="/jms/DummyMDBean"/>



The factory connection used can also be problematic in an EJB environment. In AS 6.10, it /ConnectionFactory

is a kind of unmanaged factory that works in Servlets and JSF managed beans to create direct target listeners (which are otherwise prohibited in the container).

For use in EJB it seems like you now need to use instead java:/jmsXA

(this was different in 6.0 and 5.x). For example.

@Resource(mappedName = "java:/JmsXA")
private ConnectionFactory queueConnectionFactory;




All Articles