Web服务部署得很好,我可以调用@WebMethod,但由于注入失败,我得到一个NullPointerException.
我把System.out.println(“Consructing XmlContactMapper …”);在XmlContactMapper的构造函数中(我与@autowired的一个依赖项).当我部署Web服务时,我看到调试行,所以我知道正在调用构造函数.但由于某种原因,XmlContactMapper的实例未被注入到我的ContactServiceImpl xmlMapper属性中.
关于我做错了什么的任何想法?
使用…
> Spring 3.0.5.RELEASE
> GlassFish 3.1
> jaxws-rt 2.1.4
web.xml中
<?xml version="1.0" enCoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" ID="WebApp_ID" version="3.0" Metadata-complete="true"> <display-name>contact-sib</display-name> <welcome-file-List> <welcome-file>index.HTML</welcome-file> <welcome-file>index.Jsp</welcome-file> </welcome-file-List> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:/config/bean-config.xml </param-value> </context-param> <Listener> <Listener-class>org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <servlet> <servlet-name>JaxWsEndpoint</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>JaxWsEndpoint</servlet-name> <url-pattern>/services/contact</url-pattern> </servlet-mapping></web-app>
太阳jaxws.xml
<?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>
豆-config.xml中
<?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" /></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.解决方法 像@Biji建议的那样,我认为这可能是您的ContactServiceImpl与ContactComponent之间的加载顺序问题
通常,您需要扩展SpringBeanautowiringSupport的原因是您有一些在spring容器之外实例化的bean,但您希望它通过Spring解决它的依赖关系.
由于您使用的是Glassfish Metro,因此您可以查看Metro Spring集成支持:
http://jax-ws-commons.java.net/spring/
使用此路由,com.sun.xml.ws.transport.http.servlet.WsspringServlet应该处理与Spring上下文相关的正确加载顺序.
总结以上是内存溢出为你收集整理的通过扩展SpringBeanAutowiringSupport而暴露的Web服务无法注入@Autowired依赖项全部内容,希望文章能够帮你解决通过扩展SpringBeanAutowiringSupport而暴露的Web服务无法注入@Autowired依赖项所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)