Java 您如何使用 jax-ws 公共配置 jax-ws 以与 Spring 一起工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1463295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you configure jax-ws to work with Spring using jax-ws commons?
提问by les2
In web.xml I have the following:
在 web.xml 我有以下内容:
<servlet>
<description>JAX-WS endpoint - EARM</description>
<display-name>jaxws-servlet</display-name>
<servlet-name>jaxws-servlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jaxws-servlet</servlet-name>
<url-pattern>/webServices/*</url-pattern>
</servlet-mapping>
In my application context I have the following definitions:
在我的应用程序上下文中,我有以下定义:
<bean id="helloService" class="com.foo.HelloServiceImpl">
<property name="regularService" ref="regularService" />
</bean>
<wss:binding url="/webServices/helloService" service="#helloService" />
I get a NullPointerException
when trying to access the WSDL:
我NullPointerException
在尝试访问 WSDL 时得到一个:
java.lang.NullPointerException
at com.sun.xml.ws.transport.http.HttpAdapter.<init>(HttpAdapter.java:145)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.<init>(ServletAdapter.java:76)
at com.sun.xml.ws.transport.http.servlet.ServletAdapterList.createHttpAdapter(ServletAdapterList.java:5 0)
at com.sun.xml.ws.transport.http.servlet.ServletAdapterList.createHttpAdapter(ServletAdapterList.java:4 7)
at com.sun.xml.ws.transport.http.HttpAdapterList.createAdapter(HttpAdapterList.java:73)
at com.sun.xml.ws.transport.http.servlet.SpringBinding.create(SpringBinding.java:24)
at com.sun.xml.ws.transport.http.servlet.WSSpringServlet.init(WSSpringServlet.java:46)
Strange ... appears to be a configuration error but the darn thing just dies with a NullPointerException
!!!!!!!! No logging is provided.
奇怪......似乎是一个配置错误,但该死的东西只是死了NullPointerException
!!!!!!!!不提供日志记录。
Deployed in Resin.
部署在树脂中。
采纳答案by les2
UPDATE:I finally figured out the real answer to this problem and posted it here: http://forum.springsource.org/showthread.php?p=286701
In short, Resin 3x ships with an XSD-unaware parser and you have to replace it with Apache Xerces or some other parser (see above forum post).
=========================
更新:我终于找到了这个问题的真正答案并将其发布在这里:http: //forum.springsource.org/showthread.php?p=286701
简而言之,Resin 3x 附带了一个不支持 XSD 的解析器,您必须将其替换为 Apache Xerces 或其他一些解析器(请参阅上面的论坛帖子)。
==========================
The following bean definitions get the Spring JAX-WS working (without using the "stupid" xbean / namespace magic). To come by this, I had to read the source and figure out the correct classes to use - sometimes by intentionally providing a property value that I knew would cause an exception (such as an invalid Class - this allowed me to see the stack trace which lead back to the bean class).
以下 bean 定义使 Spring JAX-WS 工作(不使用“愚蠢的”xbean / 命名空间魔法)。为此,我必须阅读源代码并找出要使用的正确类 - 有时通过故意提供一个我知道会导致异常的属性值(例如无效的类 - 这使我能够看到堆栈跟踪回到bean类)。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="webServiceMethodInterceptor"
class="com.webservice.util.interceptors.WebServiceMethodInterceptor">
<property name="userId" value="hello" />
<property name="password" value="world" />
<property name="roles" value="ROLE_ANONYMOUS,ROLE_MICKEY_MOUSE" />
</bean>
<bean id="webServiceLoggingInterceptor"
class="com.webservice.util.interceptors.LoggingInterceptor">
<property name="level" value="debug" />
</bean>
<bean id="webServiceExceptionTranslator"
class="com.webservice.util.interceptors.WebServiceExceptionTranslator"/>
<!-- The list of interceptors to apply to all web methods -->
<bean id="webServiceInterceptors" class="java.util.LinkedList">
<constructor-arg index="0">
<list>
<value>webServiceExceptionTranslator</value>
<value>webServiceLoggingInterceptor</value>
<value>webServiceMethodInterceptor</value>
</list>
</constructor-arg>
</bean>
<!-- Proxied ExampleWebService -->
<bean id="exampleWebService" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<bean class="com.webservice.ExampleWebServiceImpl">
<!-- TODO: add dependencies for web service here, for example:
<property name="someService" ref="someService" />
-->
</bean>
</property>
<property name="interceptorNames" ref="webServiceInterceptors" />
<property name="proxyTargetClass" value="true" />
</bean>
<!-- JAX-WS Endpoint for ExampleWebService -->
<bean class="com.sun.xml.ws.transport.http.servlet.SpringBinding">
<property name="url" value="/webServices/exampleService" />
<property name="service">
<bean class="org.jvnet.jax_ws_commons.spring.SpringService">
<property name="bean">
<ref local="exampleWebService" />
</property>
<property name="impl"
value="com.webservice.ExampleWebServiceImpl" />
</bean>
</property>
</bean>
Everything else is as in the tutorial linked to above (you add the JAX-WS Spring servlet in web.xml, add the servlet filter so that web service requests get routed to the jaxws servlet).
其他一切都与上面链接的教程中的一样(您在 web.xml 中添加 JAX-WS Spring servlet,添加 servlet 过滤器,以便将 Web 服务请求路由到 jaxws servlet)。
The key to using the proxied web service instance (thus enabling dependency injection, AOP, etc.) was setting proxyTargetClass="true" to force a CGLIB proxy instead of a JDK dynamic proxy (which requires an interface). JAX-WS seems to not like interfaces for some reason.
使用代理的 Web 服务实例(从而启用依赖注入、AOP 等)的关键是设置 proxyTargetClass="true" 以强制使用 CGLIB 代理而不是 JDK 动态代理(它需要一个接口)。由于某种原因,JAX-WS 似乎不喜欢接口。
I hope this helps some one!
我希望这可以帮助别人!
Regards, LES
问候, LES
回答by Asaf Mesika
LES2: Your implementation seem most complex. What's wrong with simple usage of SpringBeanAutowiringSupport, as described in Spring manual
LES2:你的实现看起来最复杂。简单使用 SpringBeanAutowiringSupport 有什么问题,如Spring 手册中所述