I try to write a transaction manager using JDBC in Spring.
my app-servlet.xml
<!-- JDBC Config -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.databaseurl}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<!-- dataSource TransactionManager -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="UserDAOImpl" class="com.project.dao.impl.UserDAOImpl">
<property name="transactionManager" ref="transactionManager"/>
</bean>
my UserDAOImpl.java
public class UserDAOImpl implements UserDAO {
//transaction manager
private DataSourceTransactionManager transactionManager;
private JdbcTemplate jdbcTemplate;
public UserDAOImpl() {
super();
DataSource dataSource = transactionManager.getDataSource();
jdbcTemplate = new JdbcTemplate(dataSource);
}
public void setTransactionManager(DataSourceTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
....
}
Even though I have transactionManager
Bean in my app-servlet, UserDAOImpl
won't be instatiated because transactionManager
is null
. Probably I miss some point but couldn't find out what is wrong.