Description
Andrew H opened SPR-16480 and commented
This may be another manifestation of #20973 which I reported last week, but it affects Java configured TransactionProxyFactoryBean and it results in multiple exceptions being logged and the creation of the context failing.
It may be reproduced with the following bean configuration in Spring 4.3.14 or 5.0.3:
transactionManager - A no-op dummy implementation of PlatformTransactionManager
javaBazBean - A TransactionProxyFactoryBean whose target is an instance of BazBean, this is declared in a @Bean
method of a @Configuration
class and expects to be injected with a PlatformTransactionManager and an instance of BarBean
barBean - A BarBean declared using @Component
, its constructor takes a FooBean
fooBean - A FooBean (declared using XML or @Component
), its constructor takes no arguments
There is no circular reference yet it complains barBean (which depends only on fooBean) is still in creation, logging this exception in the attempt to create each of the beans that depends on barBean:
"org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'barBean': Requested bean is currently in creation: Is there an unresolvable circular reference?"
As with #20973, the order of annotated bean creation plays a role:
If you declare another bean using @Component
that depends on a BarBean and its classname comes alphabetically before BarBean - say "Aardvard" for example, then the errors vanish (and a WARNING appears instead), but if you rename Aardvark to Zebra, the errors will return.
I have created and attached a small sample project to demonstrate the issue. (The main() class is named BeanCreationError).
Background information: I was attempting to replace some old XML configuration with annotation based configuration in order to reap compile-time error checking benefits. Unfortunately annotation based transaction configuration does not yet seem to provide for setting targetProxyClass at the bean level (#8346 has now been waiting 11 years for triage) hence my attempt to use Java Config with TransactionProxyFactoryBean in the hopes of reproducing the original XML configurations in Java.. This however is blocked by the above problem.
Affects: 4.3.14, 5.0.3
Attachments:
- beancreationerror_20180209.zip (9.72 kB)
Issue Links:
- Spurious WARNINGs when XML declared TransactionProxyFactoryBean's target bean depends on an annotation declared bean that depends on another bean [SPR-16427] #20973 Spurious WARNINGs when XML declared TransactionProxyFactoryBean's target bean depends on an annotation declared bean that depends on another bean