Search code examples
javaspringspring-bootcdijava-ee-6

Can I mix JEE and Spring annotations using Spring as CDI?


So, pretty straightforward question. Can I mix JEE annotations with Spring annotations on the same project? Are there any known issues with mixing both types of annotations?

For example, @Autowired and @Inject? @Named and @Qualifier?

Should Spring be able to solve injections without issues?

The reason I'm asking this is because I've encountered myself with some legacy code that uses Spring as CDI framework but 60% of the code uses JEE annotations. Some beans, however, are wired using @Autowired, there are also Spring ConfigProperties, etc.

I've already seen some weird behaviour, like classes not being injected, or @Named not being recognized by Spring, etc.


Solution

  • Spring does support CDI annotations, including @Inject, @Named, @Qualifier, ... But it comes with some limitations.

    If some class is not injected, or @Named is not recognized, I think it is likely a configuration problem.