Announcement Announcement Module
No announcement yet.
Jar having Spring JDBC code is not able to connect to App Server JNDI Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jar having Spring JDBC code is not able to connect to App Server JNDI

    I have a abc.jar file which contains a Factory class, spring-config.xml, DAOs and DTO classes. This jar file is placed in the classpath of my main web application project. The main application uses this jar to get the data from DB. The main application is deployed on Tomcat 6. I have a Datasource defined on Tomcat server which is expected to provide connection to the DAO spring beans defined inside the jar file. Unfortunately when any of the DAO bean is accessed from this jar, it is not able to create datasource bean and throws following exception:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'dataSource' defined in class path resource [spring-config.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
    at AutowireCapableBeanFactory.initializeBean(Abstract
    at AutowireCapableBeanFactory.doCreateBean(AbstractAu
    at AutowireCapableBeanFactory$
    at Method)
    at AutowireCapableBeanFactory.createBean(AbstractAuto
    at BeanFactory$1.getObject( 64)

    Here are the entries inside my spring-config.xml(this is inside a jar file along with all supporting classes):
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="jdbc/accountDS" />
    <property name="resourceRef" value="true"></property>
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
    <property name="dataSource" ref="dataSource" />
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource" ref="dataSource" />
    <bean id="accountDao" class="com.x.y.dao.AccountDAO" singleton="false">
    <property name="jdbcTemplate" ref="jdbcTemplate" />
    <bean id="accountService" class="com.x.y.impl.AccountServiceImpl" singleton="false">
    <property name="accountDao" ref="accountDao" />

    Here is the entry from tomcat server.xml:
    <Resource auth="Container" driverClassName="oracle.jdbc.driver.OracleDriver" factory="oracle.jdbc.pool.OracleDataSourceFactory" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/accountDS" password="pass" type="oracle.jdbc.pool.OracleDataSource" url="" user="user"/>

    P.S.: If I move all my code outside the jar file and place it along with the main project, everything seems to work without any configuration change!!! But my requirement forces me to use Datasource JNDI lookup from inside a jar file. Could it be security issue(not allowing a jar to access App server datasource JNDI lookup)??

    Please help.

  • #2
    Wish to add one more point: i have tried following option also but the jar is still not able to create the datasource with JNDI lookup
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="java:comp/env/jdbc/accountDS" />