How to set user/password for MDB in JBoss EAP
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 4.x
- 5.x
- 6.x
Issue
-
How do I set user/password for MDB in JBoss EAP?
-
We tried the following ejb-jar.xml for our MDB:
<?xml version="1.0" encoding="UTF-8"?> <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"> <description>JBoss Message Driven</description> <display-name>JBoss Message Driven Bean</display-name> <enterprise-beans> <message-driven> <ejb-name>MyMessageBean</ejb-name> <ejb-class>com.foo.MyMessageBean</ejb-class> <transaction-type>Bean</transaction-type> <message-destination-type>javax.jms.Queue</message-destination-type> <activation-config> <activation-config-property> <activation-config-property-name>acknowledgeMode</activation-config-property-name> <activation-config-property-value>AUTO_ACKNOWLEDGE</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>username</activation-config-property-name> <activation-config-property-value>john</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>password</activation-config-property-name> <activation-config-property-value>needle</activation-config-property-value> </activation-config-property> </activation-config> </message-driven> </enterprise-beans> </ejb-jar>However, we are receiving this error upon deployment:
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM --- ObjectName: jboss.j2ee:ear=MY-EAR.ear,jar=MY-EJB.jar,name=MyMessageBean,service=EJB3 State: FAILED Reason: org.jboss.deployment.DeploymentException: Error for ActivationSpec class org.jboss.resource.adapter.jms.inflow.JmsActivationSpec as JavaBean; - nested throwable: (java.beans.IntrospectionException: No property found for: username on JavaBean: org.jboss.resource.adapter.jms.inflow.JmsActivationSpec@250179(ra=null destination=queue/MyQueue isTopic=false tx=true durable=false reconnect=10 provider=java:/DefaultJMSProvider user=null pass=<not shown> maxMessages=1 minSession=1 maxSession=15 keepAlive=60000 useDLQ=true DLQHandler=org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler DLQJndiName=queue/DLQ DLQUser=null DLQMaxResent=5))
Resolution
-
You can set user and password by the @ActivationConfigProperty annotation in your application code:
@MessageDriven(name = "HelloWorldQueueMDB", activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/HELLOWORLDMDBQueue"), @ActivationConfigProperty(propertyName = "user", propertyValue = "quickstartUser"), @ActivationConfigProperty(propertyName = "password", propertyValue = "quickstartPwd1!"), @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") }) public class HelloWorldQueueMDB implements MessageListener { ...(snip)...or the activation configuration properties in your ejb-jar.xml:
... <message-driven> ...(snip)... <activation-config> <activation-config-property> <activation-config-property-name>acknowledgeMode</activation-config-property-name> <activation-config-property-value>AUTO_ACKNOWLEDGE</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>user</activation-config-property-name> <activation-config-property-value>quickstartUser</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>password</activation-config-property-name> <activation-config-property-value>quickstartPwd1!</activation-config-property-value> </activation-config-property> </activation-config> </message-driven> ... -
Please note that the activation configuration property is not
usernamebutuser.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
