简体   繁体   English

如何限制CDI认为是受管理的bean?

[英]How to limit what CDI considers to be managed beans?

I am coming at this question from many years of using spring and just starting to look at JEE7 and CDI. 我从使用Spring的许多年开始就遇到了这个问题,只是开始研究JEE7和CDI。

In the Spring world you have to stick @Component on a bean to turn into spring bean that spring will inject with dependencies but in CDI it seems that there is no equivalent of @Component . 在Spring的世界中,必须将@Component粘贴在bean上,以将spring注入依赖项的spring bean,但在CDI中似乎没有@Component等效项。

To me CDI seems to imply that every class in my web application will be considered a CDI bean which seems undesirable because I have lot of java classes that are not using injection and I would not want some one to just stick @Inject in those classes and have CDI do its magic. 对我而言,CDI似乎暗示着我的Web应用程序中的每个类都将被视为CDI bean,这似乎是不可取的,因为我有很多不使用注入的Java类,并且我不希望有人将@Inject留在这些类中,让CDI发挥其魔力。

Two questions: 两个问题:

  • How to restrict what CDI considers to be a managed bean in a jar file? 如何在jar文件中限制什么CDI认为是托管bean?
  • What is the benefit for CDI to consider every bean to be a managed bean? CDI将每个bean视为托管bean有什么好处?

Please see the documentation for bean-discovery-mode in beans.xml. 请在beans.xml中查看bean-discovery-mode的文档。 This attribute was only made available in JEE7 and is not available in JEE6. 此属性仅在JEE7中可用,而在JEE6中不可用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM