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.

Reply via email to