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 < [EMAIL PROTECTED]> 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 < > > [EMAIL PROTECTED]> 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/
