How declare a bean as a JNDI ref in Spring

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How declare a bean as a JNDI ref in Spring

Charles Moulliard
Hi,

In different part of the documentation, it is mentioned that a bean can be declared as a jndi reference. This could be done through Java coding as using spring configuration file. Can you help me and show me how to transpose the following code into a spring jndi bean declaration ?

"The object instance that is used to consume messages must be explicitly registered with the Registry. For example if you are using Spring you must define the bean in the spring.xml; or if you don't use Spring then put the bean in JNDI."

// lets populate the context with the services we need
// note that we could just use a spring.xml file to avoid this step
JndiContext context = new JndiContext();
context.bind("myBean", new SayService("Good Bye!"));

Regards,

Charles



Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: How declare a bean as a JNDI ref in Spring

jstrachan
On 17/03/2008, cmoulliard <[hidden email]> wrote:
>
>  Hi,
>
>  In different part of the documentation, it is mentioned that a bean can be
>  declared as a jndi reference. This could be done through Java coding as
>  using spring configuration file.

The idea is that if you can use JNDI as the registry of beans if you
are not using Spring.

If you are using Spring then its easier to use that as the 'registry'.

>  Can you help me and show me how to
>  transpose the following code into a spring jndi bean declaration ?
>
>  "The object instance that is used to consume messages must be explicitly
>  registered with the Registry. For example if you are using Spring you must
>  define the bean in the spring.xml; or if you don't use Spring then put the
>  bean in JNDI."
>
>  // lets populate the context with the services we need
>  // note that we could just use a spring.xml file to avoid this step
>  JndiContext context = new JndiContext();
>  context.bind("myBean", new SayService("Good Bye!"));

<bean id="myBean" class="com.acme.SayService'>
  <constructor-arg value="Good Bye!"/>
</bean>

If you really wanna use Spring and JNDI you can use the JNDI factory
bean in Spring to lookup a bean in JNDI


--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com