You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Alexander Wagner <al...@inside-m2m.de> on 2014/12/03 15:36:33 UTC
Inject a EJB into MBean
Hello TomEE-Comunity,
could someone give me an explanation why it is possible to inject by
@Inject but not by @EJB in a MBean?
@javax.management.MBean
@ApplicationScoped
class MyMBean {
@Inject MyService myserviceA;
@EJB MyService myserviceB;
@ManagedOperation
public void test() {
System.out.println(myserviceA); // prints the proxy
System.out.println(myserviceB); // prints null
}
}
@Stateless class MyService {}
My background is that I can use @Inject as long as my Stateless does not
implements an interface:
@Stateless class MyService implements MyInterface {}
Maybe my understanding of CDI is here not deep enough, but for now I use
normally @EJB e.g. if the EJB's implements an interface because with
@Inject the EJB can not be resolved anymore.
So for now I can not use the MyService with an interface in a MBean.
Does someone has a tip what I am doing wrong?
Best Regards
Alexander Wagner
Re: Inject a EJB into MBean
Posted by Alexander Wagner <al...@inside-m2m.de>.
Yesterday I missed to write to the mailing list, so Romain answered me
also directly. I think its ok that I publish his answer :-D
Am 03.12.2014 um 15:59 schrieb Alexander Wagner:
> I Am not sure what do you mean with "@Inject should work for EJB once a
> beans.xml added". @Inject works already but not in cases where my EJB
> for example implements an interface, than the ejb could not resolved
> anymore and I don't get the trick that it is resolvable also over CDI
> (@Inject).
Am 03.12.2014 um 16:04 schrieb Romain Manni-Bucau:
> @Inject EjbApi ejb; works with CDI. Just ensure to inject using the
> EJB "api" (ie interface for you) and not implementation
Am 03.12.2014 um 16:09 schrieb Alexander Wagner:
> Oh sry I misssed to answer to the mailing list!
>
> ah ok so in my case I resolved it by adding @LocalBean because I needed
> the impl and not only the interface...
So thank you for your help Romain!
Am 03.12.2014 um 15:46 schrieb Romain Manni-Bucau:
> Before we don't support it AFAIK, we support CDI integration but not
> EJB one. Could be added but @Inject should work for EJB once a
> beans.xml added
>
>
> Romain Manni-Bucau
> @rmannibucau
> http://www.tomitribe.com
> http://rmannibucau.wordpress.com
> https://github.com/rmannibucau
>
>
> 2014-12-03 15:36 GMT+01:00 Alexander Wagner <al...@inside-m2m.de>:
>> Hello TomEE-Comunity,
>>
>> could someone give me an explanation why it is possible to inject by @Inject
>> but not by @EJB in a MBean?
>>
>> @javax.management.MBean
>> @ApplicationScoped
>> class MyMBean {
>> @Inject MyService myserviceA;
>> @EJB MyService myserviceB;
>>
>> @ManagedOperation
>> public void test() {
>> System.out.println(myserviceA); // prints the proxy
>> System.out.println(myserviceB); // prints null
>> }
>> }
>>
>> @Stateless class MyService {}
>>
>> My background is that I can use @Inject as long as my Stateless does not
>> implements an interface:
>>
>> @Stateless class MyService implements MyInterface {}
>>
>> Maybe my understanding of CDI is here not deep enough, but for now I use
>> normally @EJB e.g. if the EJB's implements an interface because with @Inject
>> the EJB can not be resolved anymore.
>>
>> So for now I can not use the MyService with an interface in a MBean. Does
>> someone has a tip what I am doing wrong?
>>
>> Best Regards
>> Alexander Wagner
>>
Re: Inject a EJB into MBean
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Before we don't support it AFAIK, we support CDI integration but not
EJB one. Could be added but @Inject should work for EJB once a
beans.xml added
Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau
2014-12-03 15:36 GMT+01:00 Alexander Wagner <al...@inside-m2m.de>:
> Hello TomEE-Comunity,
>
> could someone give me an explanation why it is possible to inject by @Inject
> but not by @EJB in a MBean?
>
> @javax.management.MBean
> @ApplicationScoped
> class MyMBean {
> @Inject MyService myserviceA;
> @EJB MyService myserviceB;
>
> @ManagedOperation
> public void test() {
> System.out.println(myserviceA); // prints the proxy
> System.out.println(myserviceB); // prints null
> }
> }
>
> @Stateless class MyService {}
>
> My background is that I can use @Inject as long as my Stateless does not
> implements an interface:
>
> @Stateless class MyService implements MyInterface {}
>
> Maybe my understanding of CDI is here not deep enough, but for now I use
> normally @EJB e.g. if the EJB's implements an interface because with @Inject
> the EJB can not be resolved anymore.
>
> So for now I can not use the MyService with an interface in a MBean. Does
> someone has a tip what I am doing wrong?
>
> Best Regards
> Alexander Wagner
>