I am creating a spring 3 explanatory entry (xml-less) application after the tutorial here
And here is my configuration file
@Bean(name = "dataSource") public DriverManagerDataSource dataSource() { DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource(); driverManagerDataSource.setDriverClassName("org.postgresql.Driver"); driverManagerDataSource.setUrl("jdbc:postgresql://localhost:5432/test"); driverManagerDataSource.setUsername("postgres"); driverManagerDataSource.setPassword("gayle"); return driverManagerDataSource; } @Bean(name = "studentJDBCTemplate") public StudentJDBCTemplate studentJDBCTemplate() { StudentJDBCTemplate studentJDBCTemplate = new StudentJDBCTemplate(); studentJDBCTemplate.setDataSource(dataSource()); studentJDBCTemplate.setDataSourceTransactionManager(dataSourceTransactionManager()); studentJDBCTemplate.setJdbcTemplate(new JdbcTemplate()); return studentJDBCTemplate; } @Bean public DataSourceTransactionManager dataSourceTransactionManager() { DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(); dataSourceTransactionManager.setDataSource(dataSource()); return dataSourceTransactionManager; }
Now I am trying to do declarative transaction management , therefore my create() method inside StudentJDBCTemplate
public void create(String name, Integer age) { System.out.println("Creating!"); String SQL = "insert into Student (name, age) values (?, ?)"; jdbcTemplate.update(SQL, name, age); System.out.println("Created Record Name=" + name + " Age=" + age); }
Doesn't make a transaction manager soft call.
How do I achieve this? Should I declare @Aspect for this? Is there any annotation that can automatically configure when to make transactions?
source share