Seems like I am missing something: Automatically injecting a data source works, but injection of 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>
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 that the DataSourceTransactionManagerAutoConfiguration would take care of it, but it didn't. Any clues?
The sample up is on github: https://github.com/jangalinski/springboot-playground
Spring Boot is registering PlatformTransactionManager
bean, and you're trying to inject DataSourceTransactionManager
. If you'll change to proper class it will work out of the box:
@Autowired
private PlatformTransactionManager transactionManager;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With