通过@Resource批注的WebServiceContext注入问题 [英] WebServiceContext injecting issue via @Resource annotation

查看:63
本文介绍了通过@Resource批注的WebServiceContext注入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过@Resource注释注入WebServiceContext时遇到问题.我正在使用JAXWS + Spring组合.这是我使用的一段代码.

I am having issues with injecting WebServiceContext via @Resource annotation. I am using JAXWS + Spring combination. This is a piece of code I use.

@WebService 
public class AdminWSImpl {

  @Resource
  private WebServiceContext context;

...
}

我的web.xml的一部分:

Part of my web.xml:

...
<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>


<servlet>
    <description>JAX-WS endpoint of Admin Service</description>
    <display-name>JAX-WS Admin servlet</display-name>
    <servlet-name>AdminService</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>


<servlet>
    <servlet-name>context</servlet-name>
    <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>     
    <load-on-startup>2</load-on-startup>
</servlet>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

问题在于上下文始终为空!根据如何在Spring的@Transactional 弹簧中使用@Resource WebServiceContext注入-transactional我已经为上下文定义了setter,并将@Resource批注放置在setter上.

The problem is the context is always null! According to How to use @Resource WebServiceContext injection with Spring's @Transactional springs-transactional I have defined the setter for the context and put the @Resource annotation on the setter.

将@Resource批注放置在setter上的结果是此堆栈跟踪:

The result of putting @Resource annotation on the setter is this stack trace:

SEVERE: WSSERVLET11: failed to parse runtime descriptor:   javax.xml.ws.WebServiceException: Unable to create JAXBContext
javax.xml.ws.WebServiceException: Unable to create JAXBContext
    at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:171)
    at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:99)
    at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:250)
    at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:343)
    at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:205)
    at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:513)
    at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parseAdapters(DeploymentDescriptorParser.java:257)
    at com.sun.xml.ws.transport.http.DeploymentDescriptorParser.parse(DeploymentDescriptorParser.java:151)
    at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.parseAdaptersAndCreateDelegate(WSServletContextListener.java:131)
    at com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized(WSServletContextListener.java:152)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:563)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1399)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761)
    at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1500)
    at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:252)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:186)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at com.googlecode.psiprobe.Tomcat60AgentValve.invoke(Tomcat60AgentValve.java:30)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
   Caused by: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
    javax.xml.ws.WebServiceContext is an interface, and JAXB can't handle interfaces.
    this problem is related to the following location:

任何人都可以提供帮助吗?

Can anyone provide any help?

提前谢谢!

推荐答案

我找到了现在可以使用的解决方案!我在WebService批注中添加了endpointInterface属性,并添加了该类实现由wsimport生成的Admin接口.我的web.xml仍然与问题中所述的相同!

I found the solution which now works! I put the WebService annotation with endpointInterface attribute, and added the class implements Admin interface which is generated by wsimport. My web.xml remains the same as described in the question!

  @WebService(endpointInterface = "my.app.admin.Admin")
  public class AdminWSImpl implements Admin{

  @Resource
  private WebServiceContext wsContext;

  public void setWsContext(WebServiceContext wsContext) {
    this.wsContext = wsContext;
}
 }

这篇关于通过@Resource批注的WebServiceContext注入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆