简体   繁体   English

在容器外部定义数据源时,事务可以由容器管理吗?

[英]Can transactions be managed by container when datasource is defined outside the container?

Can I combine datasource, which is defined programmatically in application with container managed transaction? 我可以将应用程序中以编程方式定义的数据源与容器管理的事务相结合吗?

Context information: I would like to create datasource in runtime, because username and password for database will be retrieved from another service during startup of my service. 上下文信息:我想在运行时中创建数据源,因为在启动服务期间将从另一个服务中检索数据库的用户名和密码。 As far as I know to achieve that I should create datasource programmatically in my application. 据我所知,应该在我的应用程序中以编程方式创建数据源。

Yes, you can: for example you can add your datasource to your own transaction manager, for example using Spring transactions . 是的,您可以:例如,您可以将数据源添加到自己的事务管理器中,例如使用Spring Transactions

See this answer for more details, and here for a further example. 有关更多详细信息,请参见此答案 ;有关其他示例,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM