Tom Donohue Tom Donohue

JBoss/Wildfly: Setting a custom resource adapter for an MDB

How do you configure a Message-Driven Bean (MDB) to use a different resource adapter/connection factory from the default one?

This can be done in one of two ways.

This assumes that you’ve already defined a connection factory in your JBoss/Wildfly config, e.g.:

<pooled-connection-factory name="my-connection-factory"
    user="..." password="..." connectors="..."/>

Using annotations

Annotate your MDB class with the JBoss-specific @ResourceAdapter annotation, specifying the name of the resource adapter:

import javax.jms.MessageListener;
import org.jboss.ejb3.annotation.ResourceAdapter;

@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = { ... })
public class HelloWorldQueueMDB implements MessageListener {



If you need to send messages, just inject the connection factory, looking it up using its JNDI name:

import javax.inject.Inject;
import javax.jms.JMSConnectionFactory;

public class MyClass {

  private JMSContext context;


Using XML config

Alternatively, to avoid changing the code, you can set this in META-INF/jboss-ejb3.xml:

<?xml version="1.1" encoding="UTF-8"?>
<jboss:ejb-jar xmlns:jboss=""





What do you think? You can use Markdown in your comment.

To write code, indent each line with 4 spaces. Or, to paste a lot of code, you can put it in and share the link in your comment.