Hi Marina
Thanks for answering my question
On 29 November 2012 00:42, Marina Vatkina <marina.vatkina_at_oracle.com> wrote:
> 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.
Yes this makes sense to me.
>
>
>> 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).
I tried it out with Arquillian and the embedded GlassFish, and indeed
the @PostConstruct and @Destroy on both singleton instance, reveal the
correct up start-up sequence
>
> Otherwise use @EJB(name=...
>
>> MasterProcessor conductor;
Yes. It also injection works
@EJB(name="MasterProcessorBean") // @Singleton(name="MasterProcessBean")
>>
>> @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 think this is now a configuration and build issue.
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.sun.corba.ee.impl.orbutil.copyobject.ClassCopierOrdinaryImpl.resolve(ClassCopierOrdinaryImpl.java:167)
at com.sun.corba.ee.impl.orbutil.copyobject.ClassCopierOrdinaryImpl.doCopy(ClassCopierOrdinaryImpl.java:1193)
at com.sun.corba.ee.impl.orbutil.copyobject.ClassCopierBase.copy(ClassCopierBase.java:134)
at com.sun.corba.ee.impl.copyobject.ReflectObjectCopierImpl.copy(ReflectObjectCopierImpl.java:198)
at com.sun.corba.ee.impl.orbutil.copyobject.FallbackObjectCopierImpl.copy(FallbackObjectCopierImpl.java:66)
at com.sun.corba.ee.impl.orbutil.copyobject.FallbackObjectCopierImpl.copy(FallbackObjectCopierImpl.java:59)
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.copyObject(Util.java:771)
Incidentally, for the interested, my Gradle dependencies are:
repositories {
mavenCentral()
mavenRepo urls: '
http://repository.jboss.org/nexus/content/groups/public'
}
dependencies {
compile 'org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:1.0.0.Final'
compile 'org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:1.0.0.Final'
compile 'javax.enterprise:cdi-api:1.0'
compile 'com.sun.faces:jsf-api:2.0.3-b05'
compile 'javax.validation:validation-api:1.0.0.GA'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final'
testCompile 'org.slf4j:slf4j-simple:1.6.4'
testCompile
'org.jboss.arquillian.junit:arquillian-junit-container:1.0.2.Final'
testCompile
'org.jboss.arquillian.container:arquillian-glassfish-embedded-3.1:1.0.0.CR3'
runtime 'org.glassfish.main.extras:glassfish-embedded-all:3.1.2'
testCompile 'junit:junit:4.10'
}
I will move on something else now, because this behaviour suppose work
according the current spec EJB 3.1, and nothing is changing in the
3.2, but it will be worth trying out my example in other containers
openejb, jboss as etc
>> 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
>>
>>
--
Peter Pilgrim,
:: http://www.xenonique.co.uk/blog/ ::