Skip to content

Documentation the limitation of injecting components in @Configuration classes [SPR-12773] #17370

@spring-projects-issues

Description

@spring-projects-issues

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 class

In @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:

Referenced from: commits c7fcf7c

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions