Java 如何在jboss AS 7.2中部署的JbossWS CXF web服务中引导Spring
底部的TLDR: 根据,对于web服务,web.xml应该包含以下内容Java 如何在jboss AS 7.2中部署的JbossWS CXF web服务中引导Spring,java,spring,cxf,jboss7.x,jbossws,Java,Spring,Cxf,Jboss7.x,Jbossws,底部的TLDR: 根据,对于web服务,web.xml应该包含以下内容 <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>MyWebService</servlet-name>
<servlet-class>com.sgb.MyWebService</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyWebService</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
我想要的是:
@javax.jws.WebService(... ... ... )
@Service <-- <-- <-- ** This is Spring managed bean**
public class MyWebService implements IMyWebService
{
@Resource <-- <-- <-- **Dependency Injected by Spring**
IXyzService createService;
public CreateResponse create(CreateRequest request)
{
return createService.serve(request)
}
}
@javax.jws.WebService(……)
@服务几天前我发现这确实是可能的,所以编辑了我以前的答案。
神奇的胶水是:
@PostConstruct
public void postConstruct(){
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
因此,总结而言,需要以下几点:
1) 通过web.xml加载spring上下文
<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>
上下文配置位置
classpath*:/META-INF/spring/appContext.xml
org.springframework.web.context.ContextLoaderListener
2) 在实现CXF生成的接口的类中,用@PostConstruct注释一个方法,如下所示:
@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)
}
}
@javax.jws.WebService(……)
公共类MyWebService实现IMyWebService
{
@参考资料几天前我发现这确实是可能的,所以编辑了我以前的答案。
神奇的胶水是:
@PostConstruct
public void postConstruct(){
SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
}
因此,总结而言,需要以下几点:
1) 通过web.xml加载spring上下文
<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>
上下文配置位置
classpath*:/META-INF/spring/appContext.xml
org.springframework.web.context.ContextLoaderListener
2) 在实现CXF生成的接口的类中,用@PostConstruct注释一个方法,如下所示:
@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)
}
}
@javax.jws.WebService(……)
公共类MyWebService实现IMyWebService
{
@资源
@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)
}
}