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

huangapple go评论85阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年9月1日 07:18:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63679378.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定