@Transactional annotation can't establish dependency relationship between beans #22526
Labels
in: data
Issues in data modules (jdbc, orm, oxm, tx)
status: feedback-provided
Feedback has been provided
type: enhancement
A general enhancement
Milestone
Problem Description
I use spring framework in my projects. In my application scenario, I need to use multiple data sources. In order to ensure that each data source transaction can be consistent and isolated from each other, I defined multiple transaction managers. I add the
@Transactional
annotation to the method that requires transaction processing and specify the specific transaction manager through@Transactional("transactionManager")
.The Spring container not only manages the bean lifecycle but also includes the management of the dependencies between the beans. For example, the dependencies between the beans that is woven by the
@Autowired
and@Resource
annotations can be established, which in order to close the application correctly according to the bean dependencies.However, I find the approach that the
@Transactional
annotation specifies the 'transactionManager' qualifier does not establish the dependency between the beans, so that an exception may occur when the application is closed and the bean is destroyed. For example, when the transaction manager bean is destroyed first, if other beans that depend on the transaction manager bean have not been destroyed, there will throw exceptions.Java code below
Question
I don't understand the design that the
@Transactional
annotation can't establish the dependencies between the beans. What is the starting point of this design? If it is reasonable and acceptable, then how can we ensure that the dependencies can be established correctly?The text was updated successfully, but these errors were encountered: