问题
could someone one the current list of managed Beans or classes in Java EE 5,6,7? apart from EJBs and JSF managed beans, are they other classes ?
In the book " EJB 3 in Action", at chapter 5 (learning advanced EJB concepts) it got mentioned that:
"DI is supported only in the managed classes and that you cannot use injection in helper or utility classes."
That's why I wanted to know what are the managed beans that can in general support Dependency injection.
-please don't forget to mention online references and doc, if any - thanks in advance.
回答1:
As of EE 6:
- EJB (EJB 3.1, section 2.8 - "Relationship to to Managed Bean Specification")
- CDI (JSR-299, section 1.2.3 - "Relationship to managed beans")
- JSF (Managed Beans 1.0, section MB.1.2)
Since specifications are expected to build on top of the managed beans specification, the platform specification does not provide a comprehensive list, so you would have to review each specification included in EE 6. My evidence for JSF is the weakest, since the latest JSF specification does not explicitly state that it builds on top of the managed beans specification. However, the managed beans specification itself states that it is intended as a generalization of JSF.
That said, table EE.5-1 in the EE 6 platform specification contains the list of component classes supporting injection, PostConstruct, and PreDestroy. This list is arguably more useful than knowing which a list of component technologies that are explicitly "managed beans".
- Servlet (servlets, servlet filters, event listeners)
- JSP (tag handlers, tag library event listeners)
- JSF (scoped managed beans)
- JAX-WS (service endpoints, handlers)
- EJB (beans, interceptors)
- Managed Beans [from the managed beans specification]
- CDI (CDI-style managed beans [almost any class in an archive with beans.xml], decorators)
- Java EE platform (main class (static) [application client], login callback handler)
回答2:
Are you aware that any Java Class can be a managed bean by writing it to conform to the MBean Specification.
Your questions asks for a "current list of managed beans" in Java EE. So the short answer is that "it depends on whether the applications you are running are registering MBeans or not". You can run a JMX client (e.g. MX4J) against your JVM to find out what beans are registered.
The link I gave you for the Platform MBeans describes some that may be available by default in your JVM.
来源:https://stackoverflow.com/questions/11122127/java-ee-6-5-7-list-of-managed-beans-or-classes-ejbs-jsf-beans-and