?
Solved

JNDI lookup in Spring/Hibernate

Posted on 2006-03-23
8
Medium Priority
?
4,077 Views
Last Modified: 2013-11-24
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.
0
Comment
Question by:yongsing
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 16267016
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
 
LVL 9

Author Comment

by:yongsing
ID: 16267032
It's running like a simple Java program.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16267064
Then I doubt it. Anyway, wait to see if any other experts confirm this too.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:yongsing
ID: 16267081
How do I run the program "in the context of an app-server instance"?
0
 
LVL 92

Expert Comment

by:objects
ID: 16267497
no, instead you would use a different standalone datasource
0
 
LVL 9

Author Comment

by:yongsing
ID: 16308658
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
 
LVL 92

Expert Comment

by:objects
ID: 16309030
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
 
LVL 3

Accepted Solution

by:
el_dios earned 400 total points
ID: 16468691
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Don’ts and Dos are two important end products of software testing basics that a tester needs to regard. This article attempts to explain the principles of both.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question