Announcement Announcement Module
No announcement yet.
How to get add a JNDI datasource dynamically throught code Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get add a JNDI datasource dynamically throught code

    Hi all,
    im new to using spring and we have a requirement in the following way. We have a lookup db which first client accesses and get the info of several other schemas which he can access. He can even add or edit edit existing schema connection parameters in the lookup db. Can anyone suggest me a way of doing this. Im connecting to lookup db by passing it as resource in context.xml. Plz help me...

    thnks in advance,

  • #2
    I'm not exactly sure what you're looking for, but it sounds like you'd like to configure a JNDI data source without relying on an XML Spring configuration.

    In an XML Spring configuration, a JNDI data source is typically looked up via:

    <bean id="myDataSource"
      <property name="jndiName" value="jdbc/myDataSource" />
    The programmatic equivalent of this is:

    JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
    DataSource myDataSource = (DataSource) jndiObjectFactoryBean.getObject();
    JndiObjectFactoryBean is a Spring FactoryBean, meaning you instantiate it, pass it all its relevant properties (such as the JNDI name), and retrieve the target object (in this case a DataSource) by calling the FactoryBean's getObject() method. You could run the above snippet without ever relying on a Spring context set up via XML configuration.