WildFly and JBoss EAP 6/7 no longer support remote JNDI lookup of datasource objects. If you attempt to lookup a Datasource object from a remote client, the following error will be thrown:
ERROR: org.jboss.remoting3.MessageCancelledException Exception in thread "main" org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.NotSerializableException: org.jboss.jca.core.connectionmanager.pool.strategy.OnePool]
As an alternative, it is recommend using an EJB as facade in accessing the data source, and defining a proper contract for how the data should be accessed and managed.
JBoss 5 users
If you are running JBoss As 5 this option is still available, although discouraged. To allow it, you need to tell JBoss NOT to bind the Datasource under the “java:/”
namespace.
As a matter of fact this restricts the lookup to the same VM as the JBoss server.
Simply use’ tag <use-java-context>false</use-java-context> in your -ds.xml file
This is a sample Datasource file for mysql configured to accept remote client access
<datasources> <local-tx-datasource> <jndi-name>MySqlDS</jndi-name> <use-java-context>false</use-java-context> <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb </connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>x</user-name> <password>y</password> <metadata> <type-mapping>mySQL</type-mapping> </metadata> </local-tx-datasource> </datasources>
‘