In an application I am writing I want to do two things which I think I will require JNDI. I have started going through the JNDI tutorial on the Sun site to get a handle on how to use JNDI, but I'm hoping that someone will be able to give me a jump start by telling me what I might focus on or how I might go about designing and implementing my application. I will be using Servlets and stateless session and message-driven EJBs, and deploying on a JBoss server. In general my understanding is minimal as to how you instantiate an object so that it will be available for use by a Servlet or EJB once it has been looked up using JNDI. Is it something akin to how Servlets are brought to life via their init() method ? And if so does it involve making sure that the class has a no-arg constructor or something of the sort ? How do you know that an object is alive on the heap when we look it up with JNDI ? The first thing I want to figure out how to do is to make a log4j Logger available for use by a stateless Session EJB. My idea is to somehow initialize a log4j Logger object and bind it to a name using JNDI. Then whenever the stateless session bean comes out of the pool for use by a client it will get the Logger via a JNDI lookup and then use this logger for all of its logging. Is this a reasonable approach ? If so then how do I go about initializing a Logger object (perhaps a class which extends Logger) so that it is available for use on demand in an EJB via a JNDI lookup ? I know that you can do something like this when you load a servlet on startup of a web application (<load-on-startup> but how do you do it for a normal object ? What happens if you lookup an object and it hasn't been instantiated yet ? The other thing I want to do is to have a JavaBean (not an EJB) which is available to both servlets, a stateless session bean, and a message-driven bean. Essentially it will be a list of text messages which will need to be read by the stateless session bean and written to by the message driven bean (whether or not the servlets will need access to this bean is still unclear). At the start of a business day I will initialize this JavaBean with text messages (kept in a list of some sort) from a database fetch, and then throughout the day I will add to the list of messages using a message-driven bean (via its onMessage() method when it gets the new messages). Essentially this JavaBean will be used as a global object for use by all clients who will access it through the session bean (and possibly servlets). I'm unsure of how to create this JavaBean and make it available to the session and message driven beans which will need to access it (via a JNDI lookup I assume), but I imagine that it must be possible. I anyone can enlighten me I will certainly appreciate the help. Thanks in advance.
subject: Using JNDI - insight/design ideas/help needed