What is the use of DataSourceTransactionManager And JndiObjectFactoryBean And JdbcTemplate?
java, spring
Solution
org.springframework.jdbc.core.JdbcTemplate
Spring's using JdbcTemplate class to interact with the database. You would use this class to submit queries. It reduces boilerplate code significantly.
JdbcTemplate
org.springframework.jdbc.datasource.DataSourceTransactionManager
This would be your `TransactionManager`. `TransactionManagers` handle all of your transactional activities - running a query, wrapped in a transaction. As you can see, a `DataSource` is passed to it as a property. `DataSource` would be your `DB` conneciton.
DataSourceTransactionManager
org.springframework.jndi.JndiObjectFactoryBean
This is a `Spring` class, that handles your connections to a resource that is acquired by a `JNDI` name.
JndiObjectFactoryBean
<tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" />
This line tells your `Spring` container to scan your classes for annotations like `@Transactional`. You use `@Transactional` on a method in your `@Repository` to note that you want it to be wrapped in the `Transaction`.
Problem
What is the Use of below : ``` org.springframework.jdbc.core.JdbcTemplate org.springframework.jdbc.datasource.DataSourceTransactionManager org.springframework.jndi.JndiObjectFactoryBean <tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" /> ``` what is the use of above Classes , I am new to spring, i want to know which purposes we are using above classes below is my code:- ``` <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">Error</prop> </props></property></bean> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/WEB-INF/jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </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.DataSourceTransactionManager" scope="singleton"> <property name="dataSource" ref="dataSource" /> </bean> <tx:annotation-driven proxy-target-class="true" transaction-manager="transactionManager" /> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName" value="java:comp/env/jdbc/DbDataSource"/> <property name="lookupOnStartup" value="true"/> <property name="proxyInterface" value="javax.sql.DataSource"/></bean> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> </bean> ```