You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Sebastian Gomez <sa...@gmail.com> on 2008/03/18 17:50:23 UTC

Inject Spring Beans to cxf-se

Hello.

I'd like to inject a Spring Bean to a cxf-se service unit. If I
declare it in the xbean.xml and use a setter in the service unit's
class it is correctly initialized, but later, when I receive a message
in the service unit, I get a NullPointerException saying my bean is
"null". Is it possible that between the deployment of the service unit
and the message being received, my bean has been reset to null? I've
debugged and seen that the setter is only accessed once (during
deployment).

I've done the same thing before injecting beans to servicemix-bean
endpoints, and there it works. I wonder if it is not possible to
inject beans in other components.

Hope you can help. Best regards.

Sebastian Gomez.

Re: Inject Spring Beans to cxf-se

Posted by Guillaume Nodet <gn...@gmail.com>.
You're right, it's not supported in servicemix-cxfse.
Feel free to raise a JIRA issue and provide a patch ;-)

On Wed, Apr 2, 2008 at 4:24 PM, Fabrice Landrodie <
fabrice.landrodie@alcatel-lucent.fr> wrote:

>
> Hello Guillaume,
>
> I raised a JIRA for the problem of injected resources when using beanName
> attribut :
>
> https://issues.apache.org/activemq/browse/SM-1300 SM-1300
>
> I also made some tests with spring pooling support by using a
> ProxyFactoryBean that point to my bean (defined with singleton="false").
> But
> in this case, I always use the same instance of the bean too ... And I
> cannot use the beanName attribut in endpoint, because jbi resources cannot
> be injected to a proxy.
>
>
> Concerning smx-cxfse, Is it possible with this component to have the same
> configuration possibility as smx-bean to be able to have multi-instance
> object ?
> I don't find a similar attribut of beanName. I try to use 'scope' or
> 'singleton' attribut in the spring definition of the bean, but it seems it
> is juste created at the startup of the service unit, and no re-created
> when
> receiving a new message. Maybe it is not coded to be able to work like
> this
> ....
>
> xbean.xml for smx-cxse
>
>    <cxfse:endpoint>
>        <cxfse:pojo>
>          <bean singleton="false"
> class="org.apache.servicemix.samples.wsdl_first.PersonImpl">
>                  <property name="myProp" value="10" />
>          </bean>
>        </cxfse:pojo>
>    </cxfse:endpoint>
>
>
> Regards,
> Fabrice
>
>
> gnodet wrote:
> >
> > Could you please raise a JIRA for that ?
> > I don't have much time this week to work on that, but this is an issue
> > that
> > should be addressed asap.
> > In the mean time, have you tried using spring pooling support ?
> > It may well fit your use case as a workaround: spring would create beans
> > and
> > put them in a pool.  If you prefer, you could also not pool them at all
> by
> > implementing your own TargetSource interface (iirc).
> >
> > On Tue, Apr 1, 2008 at 1:42 PM, Fabrice Landrodie <
> > fabrice.landrodie@alcatel-lucent.fr> wrote:
> >
> >>
> >> Thank you for your answer Guillaume.
> >>
> >> I try to use spring parameters in my bean definition like you said. I
> got
> >> the same result :
> >>
> >> When using beanName and the attribut scope or singleton in the spring
> >> bean
> >> definition :
> >>
> >> <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> >> beanName="myBeanName" />
> >> <bean id="myBean" name="myBeanName" scope="prototype"
> >> class="com.examples.MyBean">
> >>                <property name="myProp" value="5" />
> >>                <property name="requestModel"
> >> value="classpath:Request.xsd"/>
> >>  </bean>
> >>
> >> The properties are well injected at startup. A new instance of the
> object
> >> is
> >> created for every request, but the properties are not injected for
> these
> >> new
> >> instances.
> >>
> >>
> >> When using bean and the attribut scope or singleton in the spring bean
> >> definition :
> >>
> >> <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> >> bean="#myBean" />
> >> <bean id="myBean" name="myBeanName" scope="prototype"
> >> class="com.examples.MyBean">
> >>                <property name="myProp" value="5" />
> >>                <property name="requestModel"
> >> value="classpath:Request.xsd"/>
> >>  </bean>
> >>
> >> The object becomes a single instance even if I set the scope to
> prototype
> >> or
> >> singleton="false". The properties are injected at startup and for every
> >> request we use the same object.
> >>
> >> It seems that the attribut bean or beanName is more important that the
> >> spring attributs ...
> >> Is this a bug or not ? this is the question :-)
> >>
> >>
> >>
> >> I also did some tests with cxf-se service unit. Here is the xbean.xml
> >> that
> >> I
> >> use with the wsld-first examples :
> >>
> >>    <cxfse:endpoint>
> >>        <cxfse:pojo>
> >>          <bean scope="prototype"
> >> class="org.apache.servicemix.samples.wsdl_first.PersonImpl">
> >>                   <property name="myProp" value="10" />
> >>         </bean>
> >>        </cxfse:pojo>
> >>    <cxfse:endpoint>
> >>
> >> In this case, the bean is always a single instance. Even if I set the
> >> singleton attribut to "false" or the scope attribut to "prototype", it
> >> always uses the same object for every requests. The properties are well
> >> injected because it is done at startup and we use the same objects for
> >> all
> >> requests.
> >>
> >> so my subsidiary question : Is it possible to have a multi-instance
> mode
> >> for
> >> cxs-se service unit like for smx-bean ?
> >>
> >> Thank you again for answers !
> >>
> >>
> >> gnodet wrote:
> >> >
> >> > The inject method will do spring job of injecting properties, but
> will
> >> > only
> >> > inject servicemix-bean specific resources into the bean.
> >> > Using the beanName should work, but you need to configure the spring
> >> side
> >> > correctly so that the bean is not a singleton and a new instance is
> >> > created
> >> > each time is is requested (try adding scope="prototype" on your bean
> >> > definition).
> >> >
> >> > On Mon, Mar 31, 2008 at 5:59 PM, Fabrice Landrodie <
> >> > fabrice.landrodie@alcatel-lucent.fr> wrote:
> >> >
> >> >>
> >> >> Hello all,
> >> >>
> >> >> I encounter mostly the same problem with smx-bean service unit (test
> >> done
> >> >> with 3.2 version)
> >> >>
> >> >> If I use the default notation to define an endpoint link to a bean,
> >> there
> >> >> is
> >> >> no problem with injecting some properties :
> >> >>
> >> >> my xbean.xml :
> >> >>
> >> >>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> >> >> bean="#myBean" />
> >> >>
> >> >>  <bean id="myBean" class="com.examples.MyBean">
> >> >>                <property name="myProp" value="5" />
> >> >>                <property name="requestModel"
> >> >> value="classpath:Request.xsd"
> >> >> />
> >> >>  </bean>
> >> >>
> >> >> in the class MyBean.java, the two properties are defined in private
> >> mode
> >> >> and
> >> >> with setter and getter.
> >> >>
> >> >> When service Unit is started, MyBean is instantiated and properties
> >> are
> >> >> injected well. Then when receiving a request, these properties are
> >> >> available
> >> >> in objet. It is important to notice that in this mode, MyBean is
> >> created
> >> >> in
> >> >> a single instance (use of bean attribut).
> >> >>
> >> >> Then I want to use the same code but with an instance per request
> >> using
> >> >> beanName attribut (cf smx-bean doc)
> >> >>
> >> >> my new xbean.xml :
> >> >>
> >> >>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> >> >> beanName="myBeanName" />
> >> >>
> >> >>  <bean id="myBean" name="myBeanName" class="com.examples.MyBean">
> >> >>                <property name="myProp" value="5" />
> >> >>                <property name="requestModel"
> >> >> value="classpath:Request.xsd"
> >> >> />
> >> >>  </bean>
> >> >>
> >> >> In this case, when service Unit is started, a first instance of
> MyBean
> >> is
> >> >> created and the properties are well injected (I put somme traces in
> >> >> constructor and setters).
> >> >>
> >> >> Then when receiving a request, a new instance is created (I can see
> >> the
> >> >> constructor trace) but properties are not injected (no traces in
> >> setters)
> >> >> and then I got a nullPointerException when trying to access
> >> requestModel
> >> >> property.
> >> >>
> >> >> I then read the source code of BeanEndpoint.java and logically, the
> >> >> inject(bean) function should be called after creating the new
> instance
> >> of
> >> >> the pojo ....
> >> >>
> >> >> Is someone having the same problem ?
> >> >>
> >> >> Guillaume, a comment would be very appreciated :-)
> >> >>
> >> >> Regards,
> >> >> Fabrice
> >> >>
> >> >>
> >> >>
> >> >> sgomez wrote:
> >> >> >
> >> >> > Hello.
> >> >> >
> >> >> > I'd like to inject a Spring Bean to a cxf-se service unit. If I
> >> >> > declare it in the xbean.xml and use a setter in the service unit's
> >> >> > class it is correctly initialized, but later, when I receive a
> >> message
> >> >> > in the service unit, I get a NullPointerException saying my bean
> is
> >> >> > "null". Is it possible that between the deployment of the service
> >> unit
> >> >> > and the message being received, my bean has been reset to null?
> I've
> >> >> > debugged and seen that the setter is only accessed once (during
> >> >> > deployment).
> >> >> >
> >> >> > I've done the same thing before injecting beans to servicemix-bean
> >> >> > endpoints, and there it works. I wonder if it is not possible to
> >> >> > inject beans in other components.
> >> >> >
> >> >> > Hope you can help. Best regards.
> >> >> >
> >> >> > Sebastian Gomez.
> >> >> >
> >> >> >
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >>
> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16396515.html
> >> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >> >>
> >> >>
> >> >
> >> >
> >> > --
> >> > Cheers,
> >> > Guillaume Nodet
> >> > ------------------------
> >> > Blog: http://gnodet.blogspot.com/
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16418176.html
> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
> > ------------------------
> > Blog: http://gnodet.blogspot.com/
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514p16447082.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Inject Spring Beans to cxf-se

Posted by Fabrice Landrodie <fa...@alcatel-lucent.fr>.
Hello Guillaume,

I raised a JIRA for the problem of injected resources when using beanName
attribut :

https://issues.apache.org/activemq/browse/SM-1300 SM-1300 

I also made some tests with spring pooling support by using a
ProxyFactoryBean that point to my bean (defined with singleton="false"). But
in this case, I always use the same instance of the bean too ... And I
cannot use the beanName attribut in endpoint, because jbi resources cannot
be injected to a proxy.


Concerning smx-cxfse, Is it possible with this component to have the same
configuration possibility as smx-bean to be able to have multi-instance
object ? 
I don't find a similar attribut of beanName. I try to use 'scope' or
'singleton' attribut in the spring definition of the bean, but it seems it
is juste created at the startup of the service unit, and no re-created when
receiving a new message. Maybe it is not coded to be able to work like this
....

xbean.xml for smx-cxse

    <cxfse:endpoint>
        <cxfse:pojo>
          <bean singleton="false"
class="org.apache.servicemix.samples.wsdl_first.PersonImpl">
		  <property name="myProp" value="10" />
          </bean>
        </cxfse:pojo>
    </cxfse:endpoint>


Regards,
Fabrice


gnodet wrote:
> 
> Could you please raise a JIRA for that ?
> I don't have much time this week to work on that, but this is an issue
> that
> should be addressed asap.
> In the mean time, have you tried using spring pooling support ?
> It may well fit your use case as a workaround: spring would create beans
> and
> put them in a pool.  If you prefer, you could also not pool them at all by
> implementing your own TargetSource interface (iirc).
> 
> On Tue, Apr 1, 2008 at 1:42 PM, Fabrice Landrodie <
> fabrice.landrodie@alcatel-lucent.fr> wrote:
> 
>>
>> Thank you for your answer Guillaume.
>>
>> I try to use spring parameters in my bean definition like you said. I got
>> the same result :
>>
>> When using beanName and the attribut scope or singleton in the spring
>> bean
>> definition :
>>
>> <bean:endpoint service="example:MyService" endpoint="myEndpoint"
>> beanName="myBeanName" />
>> <bean id="myBean" name="myBeanName" scope="prototype"
>> class="com.examples.MyBean">
>>                <property name="myProp" value="5" />
>>                <property name="requestModel"
>> value="classpath:Request.xsd"/>
>>  </bean>
>>
>> The properties are well injected at startup. A new instance of the object
>> is
>> created for every request, but the properties are not injected for these
>> new
>> instances.
>>
>>
>> When using bean and the attribut scope or singleton in the spring bean
>> definition :
>>
>> <bean:endpoint service="example:MyService" endpoint="myEndpoint"
>> bean="#myBean" />
>> <bean id="myBean" name="myBeanName" scope="prototype"
>> class="com.examples.MyBean">
>>                <property name="myProp" value="5" />
>>                <property name="requestModel"
>> value="classpath:Request.xsd"/>
>>  </bean>
>>
>> The object becomes a single instance even if I set the scope to prototype
>> or
>> singleton="false". The properties are injected at startup and for every
>> request we use the same object.
>>
>> It seems that the attribut bean or beanName is more important that the
>> spring attributs ...
>> Is this a bug or not ? this is the question :-)
>>
>>
>>
>> I also did some tests with cxf-se service unit. Here is the xbean.xml
>> that
>> I
>> use with the wsld-first examples :
>>
>>    <cxfse:endpoint>
>>        <cxfse:pojo>
>>          <bean scope="prototype"
>> class="org.apache.servicemix.samples.wsdl_first.PersonImpl">
>>                   <property name="myProp" value="10" />
>>         </bean>
>>        </cxfse:pojo>
>>    <cxfse:endpoint>
>>
>> In this case, the bean is always a single instance. Even if I set the
>> singleton attribut to "false" or the scope attribut to "prototype", it
>> always uses the same object for every requests. The properties are well
>> injected because it is done at startup and we use the same objects for
>> all
>> requests.
>>
>> so my subsidiary question : Is it possible to have a multi-instance mode
>> for
>> cxs-se service unit like for smx-bean ?
>>
>> Thank you again for answers !
>>
>>
>> gnodet wrote:
>> >
>> > The inject method will do spring job of injecting properties, but will
>> > only
>> > inject servicemix-bean specific resources into the bean.
>> > Using the beanName should work, but you need to configure the spring
>> side
>> > correctly so that the bean is not a singleton and a new instance is
>> > created
>> > each time is is requested (try adding scope="prototype" on your bean
>> > definition).
>> >
>> > On Mon, Mar 31, 2008 at 5:59 PM, Fabrice Landrodie <
>> > fabrice.landrodie@alcatel-lucent.fr> wrote:
>> >
>> >>
>> >> Hello all,
>> >>
>> >> I encounter mostly the same problem with smx-bean service unit (test
>> done
>> >> with 3.2 version)
>> >>
>> >> If I use the default notation to define an endpoint link to a bean,
>> there
>> >> is
>> >> no problem with injecting some properties :
>> >>
>> >> my xbean.xml :
>> >>
>> >>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
>> >> bean="#myBean" />
>> >>
>> >>  <bean id="myBean" class="com.examples.MyBean">
>> >>                <property name="myProp" value="5" />
>> >>                <property name="requestModel"
>> >> value="classpath:Request.xsd"
>> >> />
>> >>  </bean>
>> >>
>> >> in the class MyBean.java, the two properties are defined in private
>> mode
>> >> and
>> >> with setter and getter.
>> >>
>> >> When service Unit is started, MyBean is instantiated and properties
>> are
>> >> injected well. Then when receiving a request, these properties are
>> >> available
>> >> in objet. It is important to notice that in this mode, MyBean is
>> created
>> >> in
>> >> a single instance (use of bean attribut).
>> >>
>> >> Then I want to use the same code but with an instance per request
>> using
>> >> beanName attribut (cf smx-bean doc)
>> >>
>> >> my new xbean.xml :
>> >>
>> >>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
>> >> beanName="myBeanName" />
>> >>
>> >>  <bean id="myBean" name="myBeanName" class="com.examples.MyBean">
>> >>                <property name="myProp" value="5" />
>> >>                <property name="requestModel"
>> >> value="classpath:Request.xsd"
>> >> />
>> >>  </bean>
>> >>
>> >> In this case, when service Unit is started, a first instance of MyBean
>> is
>> >> created and the properties are well injected (I put somme traces in
>> >> constructor and setters).
>> >>
>> >> Then when receiving a request, a new instance is created (I can see
>> the
>> >> constructor trace) but properties are not injected (no traces in
>> setters)
>> >> and then I got a nullPointerException when trying to access
>> requestModel
>> >> property.
>> >>
>> >> I then read the source code of BeanEndpoint.java and logically, the
>> >> inject(bean) function should be called after creating the new instance
>> of
>> >> the pojo ....
>> >>
>> >> Is someone having the same problem ?
>> >>
>> >> Guillaume, a comment would be very appreciated :-)
>> >>
>> >> Regards,
>> >> Fabrice
>> >>
>> >>
>> >>
>> >> sgomez wrote:
>> >> >
>> >> > Hello.
>> >> >
>> >> > I'd like to inject a Spring Bean to a cxf-se service unit. If I
>> >> > declare it in the xbean.xml and use a setter in the service unit's
>> >> > class it is correctly initialized, but later, when I receive a
>> message
>> >> > in the service unit, I get a NullPointerException saying my bean is
>> >> > "null". Is it possible that between the deployment of the service
>> unit
>> >> > and the message being received, my bean has been reset to null? I've
>> >> > debugged and seen that the setter is only accessed once (during
>> >> > deployment).
>> >> >
>> >> > I've done the same thing before injecting beans to servicemix-bean
>> >> > endpoints, and there it works. I wonder if it is not possible to
>> >> > inject beans in other components.
>> >> >
>> >> > Hope you can help. Best regards.
>> >> >
>> >> > Sebastian Gomez.
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16396515.html
>> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Cheers,
>> > Guillaume Nodet
>> > ------------------------
>> > Blog: http://gnodet.blogspot.com/
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16418176.html
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514p16447082.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Inject Spring Beans to cxf-se

Posted by Guillaume Nodet <gn...@gmail.com>.
Could you please raise a JIRA for that ?
I don't have much time this week to work on that, but this is an issue that
should be addressed asap.
In the mean time, have you tried using spring pooling support ?
It may well fit your use case as a workaround: spring would create beans and
put them in a pool.  If you prefer, you could also not pool them at all by
implementing your own TargetSource interface (iirc).

On Tue, Apr 1, 2008 at 1:42 PM, Fabrice Landrodie <
fabrice.landrodie@alcatel-lucent.fr> wrote:

>
> Thank you for your answer Guillaume.
>
> I try to use spring parameters in my bean definition like you said. I got
> the same result :
>
> When using beanName and the attribut scope or singleton in the spring bean
> definition :
>
> <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> beanName="myBeanName" />
> <bean id="myBean" name="myBeanName" scope="prototype"
> class="com.examples.MyBean">
>                <property name="myProp" value="5" />
>                <property name="requestModel"
> value="classpath:Request.xsd"/>
>  </bean>
>
> The properties are well injected at startup. A new instance of the object
> is
> created for every request, but the properties are not injected for these
> new
> instances.
>
>
> When using bean and the attribut scope or singleton in the spring bean
> definition :
>
> <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> bean="#myBean" />
> <bean id="myBean" name="myBeanName" scope="prototype"
> class="com.examples.MyBean">
>                <property name="myProp" value="5" />
>                <property name="requestModel"
> value="classpath:Request.xsd"/>
>  </bean>
>
> The object becomes a single instance even if I set the scope to prototype
> or
> singleton="false". The properties are injected at startup and for every
> request we use the same object.
>
> It seems that the attribut bean or beanName is more important that the
> spring attributs ...
> Is this a bug or not ? this is the question :-)
>
>
>
> I also did some tests with cxf-se service unit. Here is the xbean.xml that
> I
> use with the wsld-first examples :
>
>    <cxfse:endpoint>
>        <cxfse:pojo>
>          <bean scope="prototype"
> class="org.apache.servicemix.samples.wsdl_first.PersonImpl">
>                   <property name="myProp" value="10" />
>         </bean>
>        </cxfse:pojo>
>    <cxfse:endpoint>
>
> In this case, the bean is always a single instance. Even if I set the
> singleton attribut to "false" or the scope attribut to "prototype", it
> always uses the same object for every requests. The properties are well
> injected because it is done at startup and we use the same objects for all
> requests.
>
> so my subsidiary question : Is it possible to have a multi-instance mode
> for
> cxs-se service unit like for smx-bean ?
>
> Thank you again for answers !
>
>
> gnodet wrote:
> >
> > The inject method will do spring job of injecting properties, but will
> > only
> > inject servicemix-bean specific resources into the bean.
> > Using the beanName should work, but you need to configure the spring
> side
> > correctly so that the bean is not a singleton and a new instance is
> > created
> > each time is is requested (try adding scope="prototype" on your bean
> > definition).
> >
> > On Mon, Mar 31, 2008 at 5:59 PM, Fabrice Landrodie <
> > fabrice.landrodie@alcatel-lucent.fr> wrote:
> >
> >>
> >> Hello all,
> >>
> >> I encounter mostly the same problem with smx-bean service unit (test
> done
> >> with 3.2 version)
> >>
> >> If I use the default notation to define an endpoint link to a bean,
> there
> >> is
> >> no problem with injecting some properties :
> >>
> >> my xbean.xml :
> >>
> >>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> >> bean="#myBean" />
> >>
> >>  <bean id="myBean" class="com.examples.MyBean">
> >>                <property name="myProp" value="5" />
> >>                <property name="requestModel"
> >> value="classpath:Request.xsd"
> >> />
> >>  </bean>
> >>
> >> in the class MyBean.java, the two properties are defined in private
> mode
> >> and
> >> with setter and getter.
> >>
> >> When service Unit is started, MyBean is instantiated and properties are
> >> injected well. Then when receiving a request, these properties are
> >> available
> >> in objet. It is important to notice that in this mode, MyBean is
> created
> >> in
> >> a single instance (use of bean attribut).
> >>
> >> Then I want to use the same code but with an instance per request using
> >> beanName attribut (cf smx-bean doc)
> >>
> >> my new xbean.xml :
> >>
> >>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> >> beanName="myBeanName" />
> >>
> >>  <bean id="myBean" name="myBeanName" class="com.examples.MyBean">
> >>                <property name="myProp" value="5" />
> >>                <property name="requestModel"
> >> value="classpath:Request.xsd"
> >> />
> >>  </bean>
> >>
> >> In this case, when service Unit is started, a first instance of MyBean
> is
> >> created and the properties are well injected (I put somme traces in
> >> constructor and setters).
> >>
> >> Then when receiving a request, a new instance is created (I can see the
> >> constructor trace) but properties are not injected (no traces in
> setters)
> >> and then I got a nullPointerException when trying to access
> requestModel
> >> property.
> >>
> >> I then read the source code of BeanEndpoint.java and logically, the
> >> inject(bean) function should be called after creating the new instance
> of
> >> the pojo ....
> >>
> >> Is someone having the same problem ?
> >>
> >> Guillaume, a comment would be very appreciated :-)
> >>
> >> Regards,
> >> Fabrice
> >>
> >>
> >>
> >> sgomez wrote:
> >> >
> >> > Hello.
> >> >
> >> > I'd like to inject a Spring Bean to a cxf-se service unit. If I
> >> > declare it in the xbean.xml and use a setter in the service unit's
> >> > class it is correctly initialized, but later, when I receive a
> message
> >> > in the service unit, I get a NullPointerException saying my bean is
> >> > "null". Is it possible that between the deployment of the service
> unit
> >> > and the message being received, my bean has been reset to null? I've
> >> > debugged and seen that the setter is only accessed once (during
> >> > deployment).
> >> >
> >> > I've done the same thing before injecting beans to servicemix-bean
> >> > endpoints, and there it works. I wonder if it is not possible to
> >> > inject beans in other components.
> >> >
> >> > Hope you can help. Best regards.
> >> >
> >> > Sebastian Gomez.
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16396515.html
> >> Sent from the ServiceMix - User mailing list archive at Nabble.com.
> >>
> >>
> >
> >
> > --
> > Cheers,
> > Guillaume Nodet
> > ------------------------
> > Blog: http://gnodet.blogspot.com/
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16418176.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Inject Spring Beans to cxf-se

Posted by Fabrice Landrodie <fa...@alcatel-lucent.fr>.
Thank you for your answer Guillaume.

I try to use spring parameters in my bean definition like you said. I got
the same result :

When using beanName and the attribut scope or singleton in the spring bean
definition :

<bean:endpoint service="example:MyService" endpoint="myEndpoint"
beanName="myBeanName" />
<bean id="myBean" name="myBeanName" scope="prototype"
class="com.examples.MyBean">
                <property name="myProp" value="5" />
                <property name="requestModel"
value="classpath:Request.xsd"/>
  </bean>

The properties are well injected at startup. A new instance of the object is
created for every request, but the properties are not injected for these new
instances.


When using bean and the attribut scope or singleton in the spring bean
definition :

<bean:endpoint service="example:MyService" endpoint="myEndpoint"
bean="#myBean" />
<bean id="myBean" name="myBeanName" scope="prototype"
class="com.examples.MyBean">
                <property name="myProp" value="5" />
                <property name="requestModel"
value="classpath:Request.xsd"/>
  </bean>

The object becomes a single instance even if I set the scope to prototype or
singleton="false". The properties are injected at startup and for every
request we use the same object.

It seems that the attribut bean or beanName is more important that the
spring attributs ...
Is this a bug or not ? this is the question :-)



I also did some tests with cxf-se service unit. Here is the xbean.xml that I
use with the wsld-first examples :

    <cxfse:endpoint>
        <cxfse:pojo>
          <bean scope="prototype"
class="org.apache.servicemix.samples.wsdl_first.PersonImpl">
	           <property name="myProp" value="10" />
         </bean>
        </cxfse:pojo>
    <cxfse:endpoint>

In this case, the bean is always a single instance. Even if I set the
singleton attribut to "false" or the scope attribut to "prototype", it
always uses the same object for every requests. The properties are well
injected because it is done at startup and we use the same objects for all
requests.

so my subsidiary question : Is it possible to have a multi-instance mode for
cxs-se service unit like for smx-bean ?

Thank you again for answers !


gnodet wrote:
> 
> The inject method will do spring job of injecting properties, but will
> only
> inject servicemix-bean specific resources into the bean.
> Using the beanName should work, but you need to configure the spring side
> correctly so that the bean is not a singleton and a new instance is
> created
> each time is is requested (try adding scope="prototype" on your bean
> definition).
> 
> On Mon, Mar 31, 2008 at 5:59 PM, Fabrice Landrodie <
> fabrice.landrodie@alcatel-lucent.fr> wrote:
> 
>>
>> Hello all,
>>
>> I encounter mostly the same problem with smx-bean service unit (test done
>> with 3.2 version)
>>
>> If I use the default notation to define an endpoint link to a bean, there
>> is
>> no problem with injecting some properties :
>>
>> my xbean.xml :
>>
>>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
>> bean="#myBean" />
>>
>>  <bean id="myBean" class="com.examples.MyBean">
>>                <property name="myProp" value="5" />
>>                <property name="requestModel"
>> value="classpath:Request.xsd"
>> />
>>  </bean>
>>
>> in the class MyBean.java, the two properties are defined in private mode
>> and
>> with setter and getter.
>>
>> When service Unit is started, MyBean is instantiated and properties are
>> injected well. Then when receiving a request, these properties are
>> available
>> in objet. It is important to notice that in this mode, MyBean is created
>> in
>> a single instance (use of bean attribut).
>>
>> Then I want to use the same code but with an instance per request using
>> beanName attribut (cf smx-bean doc)
>>
>> my new xbean.xml :
>>
>>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
>> beanName="myBeanName" />
>>
>>  <bean id="myBean" name="myBeanName" class="com.examples.MyBean">
>>                <property name="myProp" value="5" />
>>                <property name="requestModel"
>> value="classpath:Request.xsd"
>> />
>>  </bean>
>>
>> In this case, when service Unit is started, a first instance of MyBean is
>> created and the properties are well injected (I put somme traces in
>> constructor and setters).
>>
>> Then when receiving a request, a new instance is created (I can see the
>> constructor trace) but properties are not injected (no traces in setters)
>> and then I got a nullPointerException when trying to access requestModel
>> property.
>>
>> I then read the source code of BeanEndpoint.java and logically, the
>> inject(bean) function should be called after creating the new instance of
>> the pojo ....
>>
>> Is someone having the same problem ?
>>
>> Guillaume, a comment would be very appreciated :-)
>>
>> Regards,
>> Fabrice
>>
>>
>>
>> sgomez wrote:
>> >
>> > Hello.
>> >
>> > I'd like to inject a Spring Bean to a cxf-se service unit. If I
>> > declare it in the xbean.xml and use a setter in the service unit's
>> > class it is correctly initialized, but later, when I receive a message
>> > in the service unit, I get a NullPointerException saying my bean is
>> > "null". Is it possible that between the deployment of the service unit
>> > and the message being received, my bean has been reset to null? I've
>> > debugged and seen that the setter is only accessed once (during
>> > deployment).
>> >
>> > I've done the same thing before injecting beans to servicemix-bean
>> > endpoints, and there it works. I wonder if it is not possible to
>> > inject beans in other components.
>> >
>> > Hope you can help. Best regards.
>> >
>> > Sebastian Gomez.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16396515.html
>> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16418176.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.


Re: Inject Spring Beans to cxf-se

Posted by Guillaume Nodet <gn...@gmail.com>.
The inject method will do spring job of injecting properties, but will only
inject servicemix-bean specific resources into the bean.
Using the beanName should work, but you need to configure the spring side
correctly so that the bean is not a singleton and a new instance is created
each time is is requested (try adding scope="prototype" on your bean
definition).

On Mon, Mar 31, 2008 at 5:59 PM, Fabrice Landrodie <
fabrice.landrodie@alcatel-lucent.fr> wrote:

>
> Hello all,
>
> I encounter mostly the same problem with smx-bean service unit (test done
> with 3.2 version)
>
> If I use the default notation to define an endpoint link to a bean, there
> is
> no problem with injecting some properties :
>
> my xbean.xml :
>
>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> bean="#myBean" />
>
>  <bean id="myBean" class="com.examples.MyBean">
>                <property name="myProp" value="5" />
>                <property name="requestModel" value="classpath:Request.xsd"
> />
>  </bean>
>
> in the class MyBean.java, the two properties are defined in private mode
> and
> with setter and getter.
>
> When service Unit is started, MyBean is instantiated and properties are
> injected well. Then when receiving a request, these properties are
> available
> in objet. It is important to notice that in this mode, MyBean is created
> in
> a single instance (use of bean attribut).
>
> Then I want to use the same code but with an instance per request using
> beanName attribut (cf smx-bean doc)
>
> my new xbean.xml :
>
>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> beanName="myBeanName" />
>
>  <bean id="myBean" name="myBeanName" class="com.examples.MyBean">
>                <property name="myProp" value="5" />
>                <property name="requestModel" value="classpath:Request.xsd"
> />
>  </bean>
>
> In this case, when service Unit is started, a first instance of MyBean is
> created and the properties are well injected (I put somme traces in
> constructor and setters).
>
> Then when receiving a request, a new instance is created (I can see the
> constructor trace) but properties are not injected (no traces in setters)
> and then I got a nullPointerException when trying to access requestModel
> property.
>
> I then read the source code of BeanEndpoint.java and logically, the
> inject(bean) function should be called after creating the new instance of
> the pojo ....
>
> Is someone having the same problem ?
>
> Guillaume, a comment would be very appreciated :-)
>
> Regards,
> Fabrice
>
>
>
> sgomez wrote:
> >
> > Hello.
> >
> > I'd like to inject a Spring Bean to a cxf-se service unit. If I
> > declare it in the xbean.xml and use a setter in the service unit's
> > class it is correctly initialized, but later, when I receive a message
> > in the service unit, I get a NullPointerException saying my bean is
> > "null". Is it possible that between the deployment of the service unit
> > and the message being received, my bean has been reset to null? I've
> > debugged and seen that the setter is only accessed once (during
> > deployment).
> >
> > I've done the same thing before injecting beans to servicemix-bean
> > endpoints, and there it works. I wonder if it is not possible to
> > inject beans in other components.
> >
> > Hope you can help. Best regards.
> >
> > Sebastian Gomez.
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16396515.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/

Re: Inject Spring Beans to cxf-se

Posted by Sebastian Gomez <sa...@gmail.com>.
Hi.

Sorry to inform you that I have not tried injecting beans using
"beanName". I won't be able to try it today, but if no one gives you
an answer for tomorrow morning I'll try using it and I will follow you
up with my results immediately. If it happens to both of us it is
probably a bug. If not, I'll try helping you out.

Sebastian Gomez.

On Mon, Mar 31, 2008 at 5:59 PM, Fabrice Landrodie
<fa...@alcatel-lucent.fr> wrote:
>
> Hello all,
>
> I encounter mostly the same problem with smx-bean service unit (test done
> with 3.2 version)
>
> If I use the default notation to define an endpoint link to a bean, there is
> no problem with injecting some properties :
>
> my xbean.xml :
>
>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> bean="#myBean" />
>
>  <bean id="myBean" class="com.examples.MyBean">
>                <property name="myProp" value="5" />
>                <property name="requestModel" value="classpath:Request.xsd" />
>  </bean>
>
> in the class MyBean.java, the two properties are defined in private mode and
> with setter and getter.
>
> When service Unit is started, MyBean is instantiated and properties are
> injected well. Then when receiving a request, these properties are available
> in objet. It is important to notice that in this mode, MyBean is created in
> a single instance (use of bean attribut).
>
> Then I want to use the same code but with an instance per request using
> beanName attribut (cf smx-bean doc)
>
> my new xbean.xml :
>
>  <bean:endpoint service="example:MyService" endpoint="myEndpoint"
> beanName="myBeanName" />
>
>  <bean id="myBean" name="myBeanName" class="com.examples.MyBean">
>                <property name="myProp" value="5" />
>                <property name="requestModel" value="classpath:Request.xsd" />
>  </bean>
>
> In this case, when service Unit is started, a first instance of MyBean is
> created and the properties are well injected (I put somme traces in
> constructor and setters).
>
> Then when receiving a request, a new instance is created (I can see the
> constructor trace) but properties are not injected (no traces in setters)
> and then I got a nullPointerException when trying to access requestModel
> property.
>
> I then read the source code of BeanEndpoint.java and logically, the
> inject(bean) function should be called after creating the new instance of
> the pojo ....
>
> Is someone having the same problem ?
>
> Guillaume, a comment would be very appreciated :-)
>
> Regards,
> Fabrice
>
>
>
>
> sgomez wrote:
> >
> > Hello.
> >
> > I'd like to inject a Spring Bean to a cxf-se service unit. If I
> > declare it in the xbean.xml and use a setter in the service unit's
> > class it is correctly initialized, but later, when I receive a message
> > in the service unit, I get a NullPointerException saying my bean is
> > "null". Is it possible that between the deployment of the service unit
> > and the message being received, my bean has been reset to null? I've
> > debugged and seen that the setter is only accessed once (during
> > deployment).
> >
> > I've done the same thing before injecting beans to servicemix-bean
> > endpoints, and there it works. I wonder if it is not possible to
> > inject beans in other components.
> >
> > Hope you can help. Best regards.
> >
> > Sebastian Gomez.
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16396515.html
> Sent from the ServiceMix - User mailing list archive at Nabble.com.
>
>

Re: Inject Spring Beans to cxf-se

Posted by Fabrice Landrodie <fa...@alcatel-lucent.fr>.
Hello all,

I encounter mostly the same problem with smx-bean service unit (test done
with 3.2 version)

If I use the default notation to define an endpoint link to a bean, there is
no problem with injecting some properties :

my xbean.xml :

 <bean:endpoint service="example:MyService" endpoint="myEndpoint"
bean="#myBean" />

 <bean id="myBean" class="com.examples.MyBean">
  		<property name="myProp" value="5" />
  		<property name="requestModel" value="classpath:Request.xsd" />
  </bean>

in the class MyBean.java, the two properties are defined in private mode and
with setter and getter.

When service Unit is started, MyBean is instantiated and properties are
injected well. Then when receiving a request, these properties are available
in objet. It is important to notice that in this mode, MyBean is created in
a single instance (use of bean attribut).

Then I want to use the same code but with an instance per request using
beanName attribut (cf smx-bean doc)

my new xbean.xml :

 <bean:endpoint service="example:MyService" endpoint="myEndpoint"
beanName="myBeanName" />

 <bean id="myBean" name="myBeanName" class="com.examples.MyBean">
  		<property name="myProp" value="5" />
  		<property name="requestModel" value="classpath:Request.xsd" />
  </bean>

In this case, when service Unit is started, a first instance of MyBean is
created and the properties are well injected (I put somme traces in
constructor and setters).

Then when receiving a request, a new instance is created (I can see the
constructor trace) but properties are not injected (no traces in setters)
and then I got a nullPointerException when trying to access requestModel
property.

I then read the source code of BeanEndpoint.java and logically, the
inject(bean) function should be called after creating the new instance of
the pojo ....

Is someone having the same problem ?

Guillaume, a comment would be very appreciated :-)

Regards,
Fabrice



sgomez wrote:
> 
> Hello.
> 
> I'd like to inject a Spring Bean to a cxf-se service unit. If I
> declare it in the xbean.xml and use a setter in the service unit's
> class it is correctly initialized, but later, when I receive a message
> in the service unit, I get a NullPointerException saying my bean is
> "null". Is it possible that between the deployment of the service unit
> and the message being received, my bean has been reset to null? I've
> debugged and seen that the setter is only accessed once (during
> deployment).
> 
> I've done the same thing before injecting beans to servicemix-bean
> endpoints, and there it works. I wonder if it is not possible to
> inject beans in other components.
> 
> Hope you can help. Best regards.
> 
> Sebastian Gomez.
> 
> 

-- 
View this message in context: http://www.nabble.com/Inject-Spring-Beans-to-cxf-se-tp16125514s12049p16396515.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.