简体   繁体   中英

JBoss JNP as standalone server and using Resource configs from tomcat's context.xml


I have a couple of modules which now have the need of JNDI.
One of these modules runs via Apache Tomcat while the rest run standalone as J2SE application.
I was able to configure the module which uses tomcat without a problem and I've googled a bit and gathered that JBoss JNP can be a good standalone JNDI server to use.
What I fail to understand is how I can reuse the resources definitions which I have already configured (for my module which runs via tomcat in the context.xml file).
Let's say I have the following resource defined in the XML file:

  <Resource name="jdbc/dataSource" auth="Container" type="javax.sql.DataSource" 
    driverClassName="com.mchange.v2.c3p0.ComboPooledDataSource"
    url="jdbc:sqlserver://******
    username="**" password="**"/>

And the relevant code which starts the JNP is:

System.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
NamingBeanImpl jnpServer = new NamingBeanImpl();
jnpServer.start();

How can I have an InitialContext instance identify the jdbc/dataSource binding?

I don't think you can. You probably can define your jdbs resource in jboss naming context and look it up in your tomcat web app.

More info here: http://www.amitysolutions.com.au/documents/JBossTomcatJNDI-technote.pdf

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