This is an issue that gets me once every blue moon. Lets say that I have two classes
DependencyClass makes use of Spring's
@Transactional support, which is provided through AOP Proxies. This code works when I fire it up. However, if I add another implementation, and want to change the code to the following:
I get this nasty on the application startup:
NoSuchBeanDefinitionException: No matching bean of type [DependencyClass] found for dependency
The reason for this is simple. Within the Spring container, the concrete class
DependencyClass has been replaced by a proxy. Therefore, as far as the system is concerned, there is no matching bean of type
Inevitably, when this occurs, I spend too much time looking to other issues with my application context setup. However, the solution is easy and straightforward, once you realize what the problem is:
Basically, one needs to change the type back to an interface, then use named services and the
@Qualifer annotation to inject the desired dependency.
Did you like this? Please share:
The Lost Year: A Failed Experiment to Switch Away From Mac
Fed up with the Apple Keyboard, I bought a ThinkPad, installed Linux, and promptly decided that I hated computers.
Maker's Space, Manager's Space
The Grand Remote Work Experiment: A Retrospective
The COVID-19 pandemic has lead to an unexpected experiment in remote working. What has worked and why?