We have seen how easy it is to create CXF endpoints. In the previous post on WSDL first web services we had defined server endpoints as:
As a bean it is possible to inject dependencies into this endpoint. And there comes the problem. How to inject a dependency into a bean defined using the endpoint element ?
The endpoint element does not have any property child element, so the following XML would never work:
Rather than add another attribute (something like implemtor-ref), CXF uses a # at the beginning to indicate that this is a bean. The bean definition on its own can be injected with any number of dependencies.
If we are working with Spring' annotations than this code is not needed. We can keep the implementor attribute with the class name and use the @Autowired annotations. The dependencies will all be injected.
<jaxws:endpoint id="randomWs"The "randomWs" endpoint is a CXF endpoint capable of processing SOAP requests, It is also a spring managed bean.
implementor="com.ws.service.samplews_ns.SampleServiceOperationsPortTypeImpl"
address="randomService"/>
As a bean it is possible to inject dependencies into this endpoint. And there comes the problem. How to inject a dependency into a bean defined using the endpoint element ?
The endpoint element does not have any property child element, so the following XML would never work:
<jaxws:endpoint id="randomWs"I had the same problem recently and a little google search led to a solution on stack overflow. Accordingly I decided to inject a simple Spring into my endpoint:
implementor="com.ws.service.samplews_ns.SampleServiceOperationsPortTypeImpl"
address="randomService">
<property name="someProp" value="xyz"/>
</jaxws:endpoint>
publicclass SampleServiceOperationsPortTypeImpl implements SampleServiceOperationsPortType {The change in XML configuration is as follows:
privateString name;
publicString getName() {
return name;
}
publicvoid setName(String name) {
this.name = name;
}
// ...other code
}
<bean name="randomWsBean"As seen here the implementor property does not point to a class but a bean.
class="com.ws.service.samplews_ns.SampleServiceOperationsPortTypeImpl">
<property name="name" value="Hi Hello"/>
</bean>
<jaxws:endpoint id="randomWs"implementor="#randomWsBean"
address="randomService"/>
Rather than add another attribute (something like implemtor-ref), CXF uses a # at the beginning to indicate that this is a bean. The bean definition on its own can be injected with any number of dependencies.
If we are working with Spring' annotations than this code is not needed. We can keep the implementor attribute with the class name and use the @Autowired annotations. The dependencies will all be injected.