Spring-boot: automatic transaction manager configuration

It seems like I'm missing something: automatic injection of the data source works, but the injection of the DataSourceTransactionManager fails.

Dependencies:

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.2.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> </dependency> </dependencies> 

the code:

 @SpringBootApplication public class MainApplication { @Autowired private DataSource dataSource; // this fails @Autowired private DataSourceTransactionManager transactionManager; public static void main(String... args) { SpringApplication.run(MainApplication.class, args); } } 

I expected DataSourceTransactionManagerAutoConfiguration to take care of this, but it is not. Any clues?

Sample up is on github: https://github.com/jangalinski/springboot-playground

+8
spring spring-boot datasource
source share
1 answer

Spring Boot is registered by the PlatformTransactionManager bean and you are trying to enter a DataSourceTransactionManager . If you go to the appropriate class, it will work out of the box:

 @Autowired private PlatformTransactionManager transactionManager; 
+8
source share

All Articles