Announcement Announcement Module
Collapse
No announcement yet.
Jar having Spring JDBC code is not able to connect to App Server JNDI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1337)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:473)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory$1.run(AbstractAutowireC apableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 64)
    .......
    .......

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

    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="jdbc:oracle:thin:@xx.xxx.xxx.xx:1521:sid" 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" />
    </bean>

    Comment

    Working...
    X