top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to use Tomcat JNDI DataSource in Spring Web Application?

0 votes
146 views
How to use Tomcat JNDI DataSource in Spring Web Application?
posted Sep 13, 2017 by Ayush Srivastav

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

For using servlet container configured JNDI DataSource, we need to configure it in the spring bean configuration file and then inject it to spring beans as dependencies. Then we can use it with JdbcTemplate to perform database operations.

Sample configuration would be:

<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <beans:property name="jndiName" value="java:comp/env/jdbc/MyLocalDB"/>
</beans:bean>
answer Sep 14, 2017 by Sourav Kumar
...