0 votes
in Spring by
edited by

How to use Tomcat JNDI DataSource in Spring Web Application?

1 Answer

0 votes
by
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>

For complete example, please refer Spring Tomcat JNDI Example.

Related questions

0 votes
asked Jul 28, 2020 in Spring by sharadyadav1986
0 votes
asked Jul 28, 2020 in Spring by sharadyadav1986
...