JNDI lookup in Spring/Hibernate

We have a datasource called DBPool defined in a WebLogic server. On the same server, we want to run a stand-alone program to access the same datasource. The stand-alone program uses Spring/Hibernate for the database access. In this stand-alone program, we defined the following:

<bean id="MyDBPool" class="org.springframework.jndi.JndiObjectFactoryBean">
  <property name="resourceRef">
    <value>true</value>
  </property>
  <property name="jndiName">
    <value>DBPool</value>
  </property>
</bean>

When this stand-alone program runs, it will fail in the JNDI lookup. In general, is it possible for a stand-alone program to do a JNDI lookup for a datasource defined in a WebLogic server?

Thanks.
LVL 9
yongsingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
Is the stand alone program running in the context of an app-server instance or just like a normal Java program? Not sure if it is possible, maybe it should just try the simple approach instead of JNDI.
0
yongsingAuthor Commented:
It's running like a simple Java program.
0
Mayank SAssociate Director - Product EngineeringCommented:
Then I doubt it. Anyway, wait to see if any other experts confirm this too.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

yongsingAuthor Commented:
How do I run the program "in the context of an app-server instance"?
0
objectsCommented:
no, instead you would use a different standalone datasource
0
yongsingAuthor Commented:
Hi, sorry for the late reply.

In general, is it possible for a stand-alone program to do a JNDI lookup of an object in a app-server? For example, say we want to call a session bean from the stand-alone program. Wouldn't we be doing a JNDI lookup first?
0
objectsCommented:
I'd instead use spring to set the data source for your class to use then theres no need for a jndi lookup as it has a reference to its data source.
0
el_diosCommented:
Hi try this:-

      <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiEnvironment">
                  <props>
                        <prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
                        <prop key="java.naming.provider.url">t3://localhost:7001</prop>
                        <prop key="java.naming.security.principal">weblogic</prop>
                        <prop key="java.naming.security.credentials">weblogic</prop>
                  </props>
            </property>
            <property name="jndiName">
                  <value>DBPool</value>
            </property>
      </bean>

Your code is correct but will only work in the app server, you need to specify all the details. Probably this is the problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.