EJB 3.1: Does embedding beans allow resources not managed by the container?

I am using JBoss 6.1 and not fully compatible with EJB 3.1. At the moment, I cannot embed EJB in my Struts action classes (or any class that does not support Java EE Container) via @EJB , but will this be possible if the EJB 3.1 specification is fully implemented?

If not, would it be too unjustified to have it for reasons of efficiency in the foreseeable future?

+4
source share
2 answers

A container can never inject anything into an unmanaged object.

In order to be able to enter into an object, the container must control the life cycle of the object or at least participate in the management of its life cycle, so that it can receive the object at an early stage, to make an injection, if the object is created and used without any impact on container (as I suppose, the Struts beans action), then nothing will ever be inserted into the container in it. The container is not magical - it cannot just detect objects created in the whole JVM and do something with them.

Mikko's answer has a good list of types of objects that will be used for injection. If the actions of beans are not one of those that don't have bone, I'm afraid.

Now, having said all this, there is light at the end of the tunnel: it is entirely possible to write an extension for Struts that handles the injection. @EJB and @Resource injections quite closely match specific JNDI searches; the extension can reflectively search for annotated fields, and then execute the corresponding JNDI queries and enter the results. CDI injection is even easier because it has an API specifically designed to write extensions. For an example of all this, take a look at the Stripes injection enricher , which adds support for @EJB, @Resource, and @Inject to the Stripes web framework.

+4
source

It is not expected that it will have a full implementation of the specification. This is due to the Java EE v6 specification (EJB 3.1, which is a kind of sub specification of one part of Java EE 6). The following components can enter (specification, component classes):

  • Servlet: servlets, servlet filters, event listeners
  • JSP: tag handlers, tag library event listeners
  • JSF: managed beans
  • JAX-WS: Service Endpoints, Handlers
  • EJB: beans, interceptors
  • Managed Beans: Managed Beans
  • CDI: CDI beans style driven decorators
  • Java EE Platform: Core Class (Static), Login Callback Handler

Described in more detail in the specified specification, pp. 68-71.

+3
source

Source: https://habr.com/ru/post/1387678/


All Articles