firstly - since I'm new here - a short introduction:
My name is Matthias I am 28 years old and Java Programmer in the eCommerce Business. Hobbies revolve around driving & wrenching on Motorbikes, Music and everything Computer
I am currently working with a Framework that uses its own proprietary dependency injection Framework. But it is unnecessarily complicated and I really don't like it. So I decided to take a look at Spring Dependency Injection for my custom Code.
Only problem is: Both frameworks use the "javax.inject.Inject" annotation. So if I have to inject something with the other Framework, Spring starts complaining about not knowing the Bean.
I want Spring to shut up. Is there a way that I can tell Spring to ignore the @Inject Annotation? Or even all annotations since I am fine with working without Autowiring etc.
It depends quite a bit on how you are creating the application context or web application context.
To turn off all annotation processing by Spring:
- Don't create any AnnotationConfigApplicationContext instances, if you are doing so
- Remove any <context:component-scan> tags in context XMLs
- Remove any <context:annotation-driven> tags in context XMLs
- As Tushar has mentioned, remove any <mvc:annotation-driven> tags in context XMLs
To turn on or off annotation processing selectively:
- Don't annotate the new beans
- Or create AnnotationConfigApplicationContext instance with list of packages or classes to be processed by Spring. Everything else is excluded, even if it has annotations.
- Or specify <context:component-scan> with attributes base-package, include-filters and exclude-filters to control which packages and classes get annotated.
While what you want is possible, I'm wondering what happens if someday you have to make an old bean talk to a new bean or vice versa.
I feel in the long run you are introducing more technical debt by using two different DI frameworks. Sometime down the line, subsequent maintainers will wonder why there are two DI frameworks.
It's probably better to continue with the existing framework, or refactor the entire project (one class at a time, and please don't forget to write tests before starting!) to use only Spring.