Accessing Environment Props of another bean


EJB design: Accessing Environment Props of another bean

  1. Accessing Environment Props of another bean (2 messages)

    Is there a way to access the enviroment properties of another bean?
  2. I believe you cannot do that naturally...

    You could still achieve that by writing business methods in the target bean that lookup the properties and return the values...Does this make sense?


  3. I am currently developing an app where I do this very thing. In fact, it's at the core of my application. I didn't want to define resource-refs or env-entries for every bean (since many of them should have the same values and I didn't want them to get out of sync). Here is what I did:

    I have created a business, remote and home interface called ApplicationEnvironment*. In the biz interface, I have defined a method called getProperty which takes the name of the property as a string. The bean I created will prepend the ENC prefix "java:comp/env/" to the name and return the string. This way, the name of the properties is the only thing that needs to remain constant, and they only have to be defined in the deployment descriptor of the ApplicationEnvironment bean. As long as every other bean has an ejb-ref to the environment bean, it works fine.

    The interface has several other methods defined so that the only interaction your bean needs to have with the outside world takes place through the ApplicationEnvironment. It's reusable in that the interfaces are defined in separate packages, and the application-specific implementation is in the application's packages. The biz interface can also be implemented by other classes if you aren't developing EJB's.