JAXWS端点上的Spring Autorwiring不起作用

时间:2015-09-25 16:10:37

标签: java spring web-services jax-ws

我正在尝试使用JAXWS(来自JDK 7)开发SOAP Web服务。我面临的问题是自动装配。我尝试了许多博客中提到的SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext;但它不起作用。自动装配的bean仍为NULL。我的环境是:

JDK: 1.7.0_75
Spring: 4.1.7.RELEASE1
JAXWS-API: 2.2.11
JAXWS-RT: 2.2.10
JAXB-API: 2.2.12

web.xml 条目

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:spring/wsApplicationContext.xml</param-value>
</context-param>

<listener>
  <description>Spring Application Context listener. This must be loaded first</description>
  <display-name>Spring Context Config Listener</display-name>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
  <description>JAX-WS Listener. This will initialize Metro web service engine</description>
  <display-name>JAX-WS Listener</display-name>
  <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>

<servlet>
  <servlet-name>JAX-WS Servlet</servlet-name>
  <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>    
<servlet-mapping>
  <servlet-name>JAX-WS Servlet</servlet-name>
  <url-pattern>/services/*</url-pattern>
</servlet-mapping>

sun-jaxws.xml 条目

<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
  <endpoint
    name="BookService"
    implementation="com.demo.ws.endpoint.BookServiceEndpointImpl"
    wsdl="WEB-INF/wsdls/book-service.wsdl"
    service="{http://demo.app/services/book}BookService"
    port="{http://demo.app/services/book}BookServicePort"
    url-pattern="/services/books" />
</endpoints>

classpath:/spring/wsApplicationContext.xml 条目

<context:annotation-config />
<context:component-scan base-package="com.demo" />
<aop:aspectj-autoproxy proxy-target-class="true"/>

BookServiceEndpointImpl.java (网络服务端点)

@WebService(endpointInterface = "com.demo.ws.artifacts.BookServicePort")
public class BookServiceEndpointImpl implements BookServicePort {
  @Autowired
  @Qualifier(AppConstants.BOOK_SERVICE_BEAN)
  private BookService bookService;

  @PostConstruct
  public void init() {
    logger.debug(">>>>>>>>>>>>>>>>>> PostConstruct completed...");
    SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);

    logger.debug(">>>>>> bookService --> {}", bookService);
  }

  // ... The endpoint methods.
}

以上日志行打印在日志文件中,但bookService打印null

有人可以帮忙解决这个问题吗?

0 个答案:

没有答案