• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1160
  • Last Modified:

JBoss and JNDI using pojo javabean

Hello, this question is two part.

Part 1: How can I place a simple custom java object in jndi on jboss 4?  In Tomcat is could not be easier.  I simply have

< Context path="/myApp" ... >
   < Resource name="myPath/MyObject"
         location="localhost"/>  // this line will call getLocation in MyObject after instantiating it.

Now to use this I simply:

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
MyObject myObj = (MyObject) envCtx.lookup("myPath/MyObject");

Part 2: The above Tomcat config is very nice since it is app context specific.  I can now take myApp.war and copy/paste it as myAppQA.war.  No app config at all.  I simply add another context to server.xml except I change the name to myAppQA and the location="localhost" to location="www.where-ever.com".  Then when ever I deploy the either myApp or myAppQA it will get the different object even though the application code points to the same name.  In JBoss, it looks like any jndi reference is to be setup as app server wide, not app context wide.

I'm really stuck on this as I'm new to JBoss.  Thanks in advance.

  • 2
1 Solution

I believe that what you need is an <env-entry> in your web.xml file.

Best regards,

dbronk_winscape_comAuthor Commented:
But is there a way to set this at the server level like Tomcat allows?  Tomcat is beautiful about this.  In the server xml I can simply add a Resource entry to the context and then when the server comes up it will instantiate the class and inject any values placed in the Resource node into the object.  It then places that object into jndi.  This is awesome with Tomcat because now I can simply place my server configs, ie: database settings, and other server specific settings that would normally change when moving through dev, qa, prod, etc.  By adding a <env-entry> in my web.xml means that I have to configure before I deploy to each environment.  My way I configure one time and never again.

Since jboss uses tomcat I was hoping there was a way to do this.

Well, in this case you should use a similar approach.


Basically, in the above example, the Spring configuration is loaded and added to JNDI in order to be available to all other deployed applications.

The initial settings for the parameters can be specified in the MBean XML file.

JBoss also offers a web console which alowes you to invoke methods on the MBean you have created.

Hope this helps you,


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now