英文:
Can I mix JEE and Spring annotations using Spring as CDI?
问题
所以,非常直接的问题。我可以在同一个项目中混合使用JEE注解和Spring注解吗?在混合使用这两种类型的注解方面是否存在已知问题?
例如,@Autowired 和 @Inject?@Named 和 @Qualifier?
Spring是否能够在不出问题的情况下解决注入?
我之所以问这个问题,是因为我遇到了一些遗留代码,它将Spring用作CDI框架,但是其中60%的代码使用了JEE注解。然而,某些bean是使用@Autowired进行连接的,还有一些是Spring的ConfigProperties等。
我已经看到了一些奇怪的行为,比如类没有被注入,或者Spring未能识别@Named等等。
英文:
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.
答案1
得分: 3
春季确实支持 CDI 注解,包括 @Inject、@Named、@Qualifier 等等... 但是它也带有一些限制。
如果某个类没有被注入,或者 @Named 被未被识别,我认为很可能是配置问题。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论