Jan*_*ski 8 spring datasource spring-boot
好像我错过了一些东西:自动注入数据源工作,但DataSourceTransactionManager的注入失败.
依赖关系:
<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>
Run Code Online (Sandbox Code Playgroud)
码:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
我期望DataSourceTransactionManagerAutoConfiguration会处理它,但事实并非如此.有线索吗?
示例在github上:https://github.com/jangalinski/springboot-playground
Spring Boot正在注册PlatformTransactionManagerbean,你正在尝试注入DataSourceTransactionManager.如果您将改为正确的课程,它将开箱即用:
@Autowired
private PlatformTransactionManager transactionManager;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14300 次 |
| 最近记录: |