0 Replies Latest reply on Jun 10, 2014 11:33 AM by jaybozz_squarepants

    custom JNDI resource of type java.util.Properties

    jaybozz_squarepants Newbie

      In our company we're currently using Glassfish JEE Server.

      For various reasons we decided to have a look at Jboss.
      In our case that's Jboss AS 7.2


      Typical use case in our company is that we define all the configuration parameters of an application (e.g. passwords, file system paths etc.) in a single Properties object.

      This properties object is then injected into the java classes of the application via @Resource(name = "java:global/something") annotation.

      In glassfish these so-called custom JNDI Resources can be created pretty easy via the web admin console.


      In order for a smooth transition from glassfish to jboss we wanted to do the same with Jboss.
      But it seems that there's no standard way of doing so.


      By searching the Jboss sources and reading lots of forums and jboss documentation we found the following solution:


      1. Deploy  a custom module to your jboss (see attachment fo_jboss_module.zip)
          Just extract it into the modules folder of your jboss and restart it

      2. Provide the required Resources in the config file of the jboss (e.g. ..\configuration\standalone.xml)

      Config Example



      <subsystem xmlns="urn:jboss:domain:naming:1.3">



                      <object-factory name="java:global/something" module="net.flexoptix.jbossTools" class="net.flexoptix.jbossTools.PropertiesFactory">


                              <property name="some_service_url" value="https://whatever.bla.blub..."/>

                              <property name="username" value="yyyyyyyyyyyy"/>

                              <property name="password" value="zzzzzzzzzzzz"/>







      The factory class net.flexoptix.jbossTools.PropertiesFactory is contained in the custom jboss module.


      It's important to use urn:jboss:domain:naming:1.3
      This causes that class NamingSubsystem13Parser is used to parse the jboss config.
      NamingSubsystem13Parser allows to parametrize the object factory (in the example the parameters are the childs of <environment>).


      Then in your JEE application (e.g. JEE Web app) do something like this in a java class:


      public class SomeClass {


          @Resource(name = "java:global/something")

          private Properties trackingUps;




      The Jboss should automatically inject a property object with the keys some_service_url, user_name and password etc.


      Happy Hacking.




      We hope that helps somebody.
      If this is completely stupid please leave a comment.
      If this is super greate please also leave a comment.