java spring boot中的事务管理器和数据源——spring data
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36793861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TransactionManager and datasource in spring boot - spring data
提问by krmanish007
I wanted to access the Transaction Manager and datasource in my configuration in spring boot application. I am using spring-boot-starter-data-jpa
artifact.
我想在 Spring Boot 应用程序的配置中访问事务管理器和数据源。我正在使用spring-boot-starter-data-jpa
神器。
Is it possible to just autowire in the config and get its access?
是否可以在配置中自动装配并获得访问权限?
回答by leeor
You can get access to the transaction manager with:
您可以通过以下方式访问事务管理器:
@Autowired
private PlatformTransactionManager transactionManager;
For the DataSource
, out-of-the-box with the starter you chose you will get the tomcat-jdbc
datasource:
对于DataSource
您选择的开箱即用的启动器,您将获得tomcat-jdbc
数据源:
You can just inject that like this:
你可以像这样注入:
@Autowired
private DataSource dataSource;
Make sure you use the JDBC DataSource
type (javax.sql.DataSource
), and not a specific implementation.
确保使用 JDBCDataSource
类型 ( javax.sql.DataSource
),而不是特定的实现。