Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过扩展SpringBeanAuthoringSupport公开的web服务无法注入@Autowired依赖项_Spring - Fatal编程技术网

通过扩展SpringBeanAuthoringSupport公开的web服务无法注入@Autowired依赖项

通过扩展SpringBeanAuthoringSupport公开的web服务无法注入@Autowired依赖项,spring,Spring,通过扩展SpringBeanAutowiringSupport而公开的web服务无法注入@Autowired依赖项 Web服务部署良好,我能够调用@WebMethod,但由于注入失败,我得到了一个NullPointerException 我把System.out.println(“构造XmlContactMapper…”)放进去。当我部署web服务时,我会看到调试行,因此我知道正在调用构造函数。但是由于某些原因,XmlContactMapper的实例没有被注入到我的ContactServiceI

通过扩展SpringBeanAutowiringSupport而公开的web服务无法注入@Autowired依赖项

Web服务部署良好,我能够调用@WebMethod,但由于注入失败,我得到了一个NullPointerException


我把
System.out.println(“构造XmlContactMapper…”)放进去。当我部署web服务时,我会看到调试行,因此我知道正在调用构造函数。但是由于某些原因,XmlContactMapper的实例没有被注入到我的ContactServiceImpl xmlMapper属性中

你知道我做错了什么吗

使用

  • 弹簧3.0.5.1释放
  • 玻璃鱼3.1
  • JAXWSRT2.1.4
web.xml 登录中
正如@Biji所建议的,我认为这可能是您的ContactServiceImpl与ContactComponent之间的加载顺序问题

通常,您需要扩展SpringBeanAuthoringSupport的原因是您有一些在Spring容器外部实例化的bean,但您希望它通过Spring解决其依赖关系

由于您使用的是Glassfish+Metro,您可以看看Metro-Spring集成支持:


使用此路由,com.sun.xml.ws.transport.http.servlet.WSSpringServlet应该根据您的Spring上下文考虑正确的加载顺序。

侦听器的顺序很重要。必须在WSServletContextListener
之前定义
ContextLoaderListener

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

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>

上下文配置位置
类路径:wsContext.xml
org.springframework.web.context.ContextLoaderListener
com.sun.xml.ws.transport.http.servlet.WSServletContextListener

正如Zeemee所说,侦听器定义的顺序至关重要。此外,我还必须在
web.xml
中添加
,因为Tomcat 8.0.26本身并不尊重订单。

有趣的是,我不知道您实际上可以扩展SpringBeanAutowiringSupport并将字段连接到其中-我可以建议打开调试级别,看看Spring在这里打印了什么内容吗,这可以为可能出现的错误提供一个很好的方向听起来您的webservice类
ContactServiceImpl
在Spring容器加载之前被实例化了。当我部署web服务时,我确实首先看到了ContactServiceImpl中的调试行。所以这个问题似乎与时间有关。ContactServiceImpl bean是在spring上下文中定义的吗?ContactServiceImpl不是在我的spring上下文(bean配置)中定义的。我确实尝试在那里定义它,注入工作正常,但该实例不是从/services/contact servlet URL调用的。问题似乎是我的端点在spring上下文之前就已经初始化了。所以SpringBeanauthoring支持没有效果。我已经更新了我的帖子,加入了提到这一点的调试日志。用WSSpringServlet替换WSServlet成功了。我去掉了SpringBeanAutowiringSupport扩展和sun-jaxws.xml。我像在bean-congif.xml中一样配置了ContactServiceImpl bean。然后,我将该bean连接到jaxws servlet,并通过以下示例和示例公开该服务。谢谢
<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
           version="2.0">

  <endpoint name="ContactService" 
            implementation="com.bb.sc.sib.contact.ContactServiceImpl" 
            url-pattern="/services/contact"/>

</endpoints>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context ="http://www.springframework.org/schema/context"
       xmlns:tx = "http://www.springframework.org/schema/tx"
       xmlns:p = "http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-3.0.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <context:component-scan base-package="com.bb.sc.sib.contact"/>
    <context:annotation-config/>

    <bean id="xmlMapper" class="com.bb.sc.sib.contact.XmlContactMapper"/>

</beans>
@WebService (endpointInterface="com.bb.sc.sei.contact.ContactService", serviceName="JaxWsContactService")
public class ContactServiceImpl extends SpringBeanAutowiringSupport implements ContactService {
    @Autowired
    private ContactComponent contactComponent;
    @Autowired
    private MapperFacade xmlMapper;
INFO: 10:56:40.073 [admin-thread-pool-4848(419)] DEBUG o.s.w.c.s.SpringBeanAutowiringSupport - Current WebApplicationContext is not available for processing of ContactServiceImpl: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:wsContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>