You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Morten Steffensen <ms...@emercos.com> on 2012/07/18 18:08:21 UTC

Spring/EJB integration on TomEE - @Resource problem

Hi,

I have a web application using Spring, and loading a Stateless Ejb by using
ClassPathApplication. 
The Ejb is supposed to make a facade for Remoting the application. 

The Ejb uses @Resource for referring back to a Spring bean (like
CineplexImpl in the spring integration example). When deploying on Tomee I
get the exception:
"No provider available for resource-ref 'null' of type
'com.myapp.components.IdentityCheckComponent' for 'MyAppStateLessImpl'."

The junit test calling a method on the Ejb works running locally in my IDE.

There is probably some race condition of loading beans and EJB i guess.. ?
Can anybody give me a hint ?

/Morten

--
View this message in context: http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Romain Manni-Bucau <rm...@gmail.com>.
just set the OpenEJB.getTransactionManager() returned value as tx mgr in
spring ctx ;)

- Romain


2012/8/12 Morten Steffensen <ms...@emercos.com>

> Hi Romain,
>
> Oh my mistake - you are right it also works for me. I was too fast, and put
> a breakpoint with Intellij in the springInCdi() test method. Then when
> inspecting the cdi.bean() the prop is null. I assume this is because the
> springbean is a proxy. As soon as i read the getProp() i actually get the
> expected value.
>
> Ok great. Now i have to figure out how get the transactiontional context
> from EJB/CDI to spring...
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656812.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Morten Steffensen <ms...@emercos.com>.
Hi Romain,

Oh my mistake - you are right it also works for me. I was too fast, and put
a breakpoint with Intellij in the springInCdi() test method. Then when
inspecting the cdi.bean() the prop is null. I assume this is because the
springbean is a proxy. As soon as i read the getProp() i actually get the
expected value. 

Ok great. Now i have to figure out how get the transactiontional context
from EJB/CDI to spring...



--
View this message in context: http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656812.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Romain Manni-Bucau <rm...@gmail.com>.
the comment is to say "don't use cdi to manage @PostConstruct" since spring
already handles it (same for predestroy normally)

i added a property to my test and it works. Do you use a @Spring qualifier?

- Romain


2012/8/10 Morten Steffensen <ms...@emercos.com>

> Hi Romain,
>
> back from vacation and looking at your example. I modified it so that
> MySpringBean1 has a String property which is set in app-ctx.xml. Setting a
> breakpoint in your testcase, this property seems  to be null - not copied
> over from spring context to CDI context.. It just seem that a MySpringBean1
> instance has been created and injected in MyCdiBean1. I set a breakpoint in
> SpringBean create method, and this is apparently not called..  I wonder if
> that is the problem. What does your comment 'postconstruct managed by
> spring' mean ?
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656770.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Morten Steffensen <ms...@emercos.com>.
Hi Romain,

back from vacation and looking at your example. I modified it so that
MySpringBean1 has a String property which is set in app-ctx.xml. Setting a
breakpoint in your testcase, this property seems  to be null - not copied
over from spring context to CDI context.. It just seem that a MySpringBean1
instance has been created and injected in MyCdiBean1. I set a breakpoint in
SpringBean create method, and this is apparently not called..  I wonder if
that is the problem. What does your comment 'postconstruct managed by
spring' mean ?



--
View this message in context: http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656770.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Morten Steffensen <ms...@emercos.com>.
Super - thanks alot! I got the code, but will look at it later. 

--
View this message in context: http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656391.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Romain Manni-Bucau <rm...@gmail.com>.
pushed some idea here  https://github.com/rmannibucau/cdi-spring-bridge

Note: it uses cdi and works on tomee and should work on weld but it is not
100% CDI compliant (i don't know if CanDI could support it) but since you
were able to use some OpenEJB magic i guess that's not an issue.

- Romain


2012/7/18 Morten Steffensen <ms...@emercos.com>

> Ok - sounds great. I have ckecked-out the openejb project, and will try to
> figure out how it can be done. Keep up the nice work - it is much
> appreciated .
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656388.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Morten Steffensen <ms...@emercos.com>.
Ok - sounds great. I have ckecked-out the openejb project, and will try to
figure out how it can be done. Keep up the nice work - it is much
appreciated .

--
View this message in context: http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656388.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Easy answer: TomEE is stable for production and used on a lot of projects.

Now the spring-cdi one (a bit longer ;)): what i'd do: i'd write a cdi
producer to create my app context and a disposer to close it. I'd write an
extension to get the application then register all spring beans as cdi
beans.

It should work pretty easily. I'll try to make a poc if i find some time.

- Romain


2012/7/18 Morten Steffensen <ms...@emercos.com>

> Hi Romain,
>
> Thanks for a quick reply!
>
> no reason for not using CDI. I know spring and had to port an old app from
> ejb2. So i stumbled over obenejb, and was happy for the easy integration
> into unit testing. I thought the "spring integration" example was a nice
> approach. I will try using CDI.
>
> I use XA transactions and bitronix. Do you see any problems here concerning
> CDI (sorry for my ignorence) ?
> I thing I read that CDI/spring mix is a bad idea in e.g. JBoss...
>
> And finally - do you have any working examples for using spring/cdi - more
> precisely - is spring booting cdi, or the other way arround. And what about
> transactional context.. where does this come from ?
>
> OpenEjb seems  great for testing, but what about production ? Is it a
> stable
> solution ?
>
> /Morten.
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656384.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Morten Steffensen <ms...@emercos.com>.
Hi Romain,

Thanks for a quick reply!

no reason for not using CDI. I know spring and had to port an old app from
ejb2. So i stumbled over obenejb, and was happy for the easy integration
into unit testing. I thought the "spring integration" example was a nice
approach. I will try using CDI.

I use XA transactions and bitronix. Do you see any problems here concerning
CDI (sorry for my ignorence) ?
I thing I read that CDI/spring mix is a bad idea in e.g. JBoss... 

And finally - do you have any working examples for using spring/cdi - more
precisely - is spring booting cdi, or the other way arround. And what about
transactional context.. where does this come from ?

OpenEjb seems  great for testing, but what about production ? Is it a stable
solution ?

/Morten.

--
View this message in context: http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379p4656384.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: Spring/EJB integration on TomEE - @Resource problem

Posted by Romain Manni-Bucau <rm...@gmail.com>.
yes,

the funny thing is it should work providing openejb in a webapp in
tomcat....but well you'll loose a lot of tomee features.

What i wonder is why using this (now old) integration? why not using an
existing (or one you write since it is easy) cdi extension simply adding to
cdi spring beans? This way you'll be able to @Inject your spring beans
easily.

wdyt?

- Romain


2012/7/18 Morten Steffensen <ms...@emercos.com>

> Hi,
>
> I have a web application using Spring, and loading a Stateless Ejb by using
> ClassPathApplication.
> The Ejb is supposed to make a facade for Remoting the application.
>
> The Ejb uses @Resource for referring back to a Spring bean (like
> CineplexImpl in the spring integration example). When deploying on Tomee I
> get the exception:
> "No provider available for resource-ref 'null' of type
> 'com.myapp.components.IdentityCheckComponent' for 'MyAppStateLessImpl'."
>
> The junit test calling a method on the Ejb works running locally in my IDE.
>
> There is probably some race condition of loading beans and EJB i guess.. ?
> Can anybody give me a hint ?
>
> /Morten
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/Spring-EJB-integration-on-TomEE-Resource-problem-tp4656379.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>