• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Dep Injection how to ignore Annotation

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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.

Thanks a lot

Regards,
Matthias
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure, if you want to remove all the Spring annotation support then you could comment
"<mvc:annotation-driven />" this line from servlet setting file.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch, Matthias!

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.
reply
    Bookmark Topic Watch Topic
  • New Topic