I found out a few days back that this is indeed possible, so editing my previous answer. The magic glue is this:
@PostConstruct
public void postConstruct(){
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
So to summarize, the following pieces are needed:
1) Load the spring context via web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/META-INF/spring/appContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
2) Annotate a method with @PostConstruct in the class that implements the interface generated by CXF like so:
@javax.jws.WebService(... ... ... )
public class MyWebService implements IMyWebService
{
@Resource <-- <-- <-- **Dependency Injected by Spring**
IXyzService createService;
@PostConstruct
public void postConstruct(){
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
public CreateResponse create(CreateRequest request)
{
return createService.serve(request)
}
}
The above info is courtesy of this link:How to initialize Spring Framework inside CXF JAX-WS service Hope this helps...
=== PREVIOUS ANSWER ===
Well. Turns out, it cannot be done - The version I have now working is the correct way - as far as I can tell.
Explanation:
Apache CXF can be used with OR WITHOUT Spring.
JbossCXF (in AS 7.x or EAP 6.x) uses CXF as the default web service stack WITHOUT Spring. So when Jboss invokes the class that implements the web service interface (MyWebService above in my example annotated with @WebService(), the spring container is NOT yet initiated.... as the configuration in web.xml or jboss-cxf.xml does not allow for it.
So, the Spring container needs to be manually started inside the SEI impl class due to which the service class itself cannot be a spring managed bean (obviously).
Hence, the need to instantiate service beans inside the method using the getBean() method.
Once the service Beans are instantiated, their dependencies are automatically managed by the spring container as they are all now spring managed bean.
Hope this helps someone.
SGB