-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Documentation the limitation of injecting components in @Configuration classes [SPR-12773] #17370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Juergen Hoeller commented This sounds like a strange initialization order issue. Could you please try to extract a minimal test app which reproduces the problem, and submit it here? Juergen |
Amit Gadkari commented Tomcat web application for recreating problem of proxy not been created for autowired beans in As per Maten Denium, proxy will not created for autowired beans injected in In that case this should be documented in reference documentation and injection of beans in |
Amit Gadkari commented I did clean compile and ran application on tomcat for 10 times and all 10 times I did not got proxy of CustmerService. I have attached sample application sample-tomcat as an attachment with this email. Import project as maven project and run it on TC or tomcat server |
Janning Vygen commented Don't know if it relates to this bug, but I have similar problems. When I upgrade from 4.1.4 to 4.1.5 the application startup fails. I have a configuration like this:
and a controller like this:
Exception goes like this:
Strange. Never had regressions like this with spring. I can try to isolate a test case if it helps. It seems to me that the order of initialization is wrong. Spring tries to create ImgController before creating the other beans. |
Juergen Hoeller commented Janning Vygen, I'm afraid you're running into #17341, an unfortunate regression in 4.1.5 (due to the lack of a unit test for overlapping bean names in configuration classes). This has been fixed in recent 4.1.6 snapshots already. Juergen |
Stéphane Nicoll commented I can see that you are accessing your service in the There is no guarantee that all proxies will be created at this point which is a reason why @Transactional methods should not be used in initialization callbacks Let me know If I miss anything. |
Amit Gadkari commented In CustomerTask in Postconstruct, I was checking if proxy of customerService is injected or not. This postconstruct was only for debugging purpose Main problem was in SpringScheduledTaskConfig class which is annotated by For verification I put System.out in If I comment following code from SpringScheduledTaskConfig (which is annotated with
I think that its documentation problem. |
Amit Gadkari commented Documentation problem which needs to be specified in Reference documentation |
Stéphane Nicoll commented sorry, it would haven been nice to provide a project that exhibits the actual problem rather than asking us to look into 10 different classes to find out what the problem might be. dependencies in configuration classes should be of the simplest kind only so wiring your service there forces an early initialization that may lead to such situation. Looking whether the proxy has been created or not during the startup phase is pointless anyway as I mentioned in my previous comment. |
Stéphane Nicoll commented The reference guide has been updated to put an explicit note regarding the use of "hard-wiring" in configuration classes. |
Uh oh!
There was an error while loading. Please reload this page.
Amit Gadkari opened SPR-12773 and commented
I have
@Configuration
class with@EnableAspectJAutoProxy
.In this class I have injected
@Autowired
@Qualifier
(value="customerService")private CustomerService customerService;
Code for CustomerService is as follows
@Service
(value="customerService")public class CustomerServiceImpl implements CustomerService
In this customerService class I have
@Transactional
method which is also present in Service Interface classIn
@Configuration
class instead of proxy instance of CustomerService I get instance of customerServiceImpl. Hence transaction management is not working in application.If I use applicationContext.getBean("customerService", CustomerService.class) and print classname name then also I am getting CustomerServiceImpl and not proxy.
I ran application 10 times
a) 7 times I got instance of customerServiceImpl
b) 3 times I got instance of proxy
My application works fine when I get instance of proxy
I think this is bug in Spring JavaConfig
Affects: 4.1.5
Attachments:
Issue Links:
@Configuration
classes with post-processor definitionsReferenced from: commits c7fcf7c
The text was updated successfully, but these errors were encountered: