users@ejb-spec.java.net

[ejb-spec users] Re: EJB References in EJB 3.2

From: Marina Vatkina <marina.vatkina_at_oracle.com>
Date: Wed, 28 Nov 2012 16:42:57 -0800

Peter,

Peter Pilgrim wrote:
> Hello
>
> How does EJB 3.2 now handle EJB References?
>

The same way as EJB 3.1. Nothing has been changed in this area.
> One of the constant questions on stackflow is about dependent
> injection of session bean inside another session bean in order to
> invoke some behaviour.
>
> I have been playing with Arquillian and checking the GlassFish 3
> implementation. The following does not currently work in my
> integration tests.
>
> import javax.annotation.*;
> import javax.ejb.*;
> import java.util.Properties;
>
> @Startup
> @Singleton(name="MasterProcessor")
> @EJB(name="java:app/MasterProcessor", beanInterface=MasterProcessor.class)
>

The above line is not required
> public class MasterProcessorBean implements MasterProcessor {
> private Properties properties = new Properties();
>
> @PostConstruct
> public void appStartUp() {
> properties.putAll(System.getProperties());
> }
>
> @PreDestroy
> public void appShutdown() {
> properties.clear();
> }
>
> /* ... */
> }
>
>
> @Startup
> @Singleton
> @DependsOn("MasterProcessor")
>
The above line is not required as the bean class already declares a
dependency via injection.

> public class DetailSection implements Facilitator {
>
> @EJB(mappedName = "java:app/MasterProcessor")
>

Try just @EJB (unless there is more than one bean type that exposes this
interface).

Otherwise use @EJB(name=...
> MasterProcessor conductor;
>
> @Override
> public MasterProcessor getMasterProcessor() {
> return conductor;
> }
>
> /* ... */
> }
>
> What I want to know is, is supposed to work in the upcoming EJB 3.2?
>

It should be working now with any EJB 3.1 compliant container.

-marina
> I assume the singletons are in the same application and module; if the
> implementation details are considered correctly then the EJB container
> should be able to inject MasterProcessor proxy into the DetailSection
> proxy.
>
> http://stackoverflow.com/questions/10089957/explicite-local-ejb-not-injected-with-arquillian
>
>