简体   繁体   中英

JBoss datasource creation

JBoss creates datasource from *ds.xml files and I want to do this without such an xml file and still make JBoss provide datasources through jndi.

The code that I have written registers 4 mbeans :

RARDeployment at jboss.jca:service=ManagedConnectionFactory,name=" + dataSourceJndiUrl

JBossManagedConnectionPool at "jca:service=ManagedConnectionPool,name=" + dataSourceJndiUrl

TxConnectionManager at "jboss.jca:service=XATxCM,name=" + dataSourceJndiUrl

WrapperDataSourceService at "jboss.jca:service=DataSourceBinding,name=" + dataSourceJndiUrl

I would like to be able to retrieve a DataSource objects using the following code:

InitialContext ctx = null;
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup(dataSourceJndiUrl);

Can someone tell me if the above is a correct approach and if yes what else needs to be done in order for it to work?

yes, is possible and is the best way to do it.

In my case, I needed to use an standalone-full configuration (EAP 6.2). The first you need is the correct JDBC for your DB, for example I used the ojdbc6.jar. Copy this Jar into ${JBOSS_HOME}/modules/ com/oracle /main/ . The JDBC must be with an module.xml, to make it valid for JBoss. To me, this was a correct configuration of the module.xml:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.oracle">
    <resources>
        <resource-root path="ojdbc6.jar"/>
    </resources> 
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/> 
    </dependencies>
</module>

Then, on the standalone-full.xml file you will find a tag with the urn of datasources, inside of that tag a datasources tag, and inside a drivers tag. You need to add this new JDBC, to me this was a succesfull configuration:

<drivers>
  <driver name="Oracle" module="com.oracle">
    <xa-datasource-class>com.oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
  </driver>
</drivers>

Start the JBoss with that configuration and go to the Profile > Connector > Datasources. Add a new one with your own configuration (JNDI, User, Password, etc...), dont forget to add on properties the URL to your DB. Then, you will be able to use the JNDI for the DataSource.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM