没有sun-jaxws.xml的Tomcat上的JAX-WS Web服务 [英] JAX-WS Web service on Tomcat without sun-jaxws.xml
问题描述
我正在尝试在Tomcat上部署基于JAX-WS的Web服务时最小化所需的配置。随着Servlet 3.0的引入(由Tomcat 7+支持), web.xml
可以被抛出,但仍然有 sun-jaxws.xml
。这个博文很有意思:
I am trying to minimize required configuration while deploying JAX-WS-based Web service on Tomcat. With the introduction of Servlet 3.0 (supported by Tomcat 7+), web.xml
can be thrown out, but there is still sun-jaxws.xml
. This blog post is interesting:
当然,使用jax-ws注释,即使配置
sun-jaxws.xml也可以是可选的使它完全描述符
免费,但这需要指定一个默认的url模式,如
JSR-109或自定义模式,如Jersey REST服务,在JAX-WS
规范中。
Of course, with the use of jax-ws annotations, even configuration sun-jaxws.xml can be made optional making it completely descriptor free, but that requires specifying a default url-pattern like in JSR-109 or custom pattern like in Jersey REST services, in the JAX-WS specification.
是否可以在Tomcat上避免 sun-jaxws.xml
,以及如何?
Is it possible to avoid sun-jaxws.xml
on Tomcat, and how?
推荐答案
可悲的是,配置必须存在某处。根据消息来源,这是强制性的。信不信由你, sun-jaxws.xml文件的位置是硬编码的到/WEB-INF/sun-jaxws.xml(谢谢,伙计们@Metro)。
Sadly, the configuration must exist somewhere. That is mandatory, per the source. Believe it or not, the location of the sun-jaxws.xml file is hard-coded to /WEB-INF/sun-jaxws.xml (thanks, guys @ Metro).
实际上,您需要控制以下类别
需要做什么:
-
WSServletContextListener
显然不会被扩展。此侦听器根据sun-jaxws.xml和jaxws-catalog文件执行大多数初始化。就像我之前提到的,位置是硬编码的。所以你在这里阻力最小的路径是
WSServletContextListener
will obviously not be extended. This listener performs most of the initializations per the sun-jaxws.xml and jaxws-catalog file. Like I mentioned earlier, the location is hard coded. So your path of least resistance here is to
-
实现你自己的vanilla servlet监听器(带有
@WebListener
)并调用新的WSServletContextListener()
。然后,您将自己的contextInitialized(ServletContext ctxt)
和contextDestroyed()
方法委派给您的实例中的方法WSServletContextListener
。
implement your own vanilla servlet listener (with
@WebListener
) and call anew WSServletContextListener()
. You'll then delegate your owncontextInitialized(ServletContext ctxt)
andcontextDestroyed()
methods to the ones in your instance ofWSServletContextListener
.
使用 @XmlRootElement
类,即时生成监听器实例化的文件'll代表sun-jaxws文件(我会在短时间内提供一个这样的样本,现在没有时间:))。
Generate the file on instantiation of the listener, on the fly, using an @XmlRootElement
class that'll represent the sun-jaxws file(I'll provide a sample of this in a short while, don't have the time right now :) ).
对于这样一个可有可无的便利,IMO来说很麻烦,但它应该在理论上起作用。我会写一些样本,看看他们很快就会播放。
It's a lot of trouble for such a dispensable convenience, IMO, but it should work in theory. I'll write some samples and see how they play shortly.
这篇关于没有sun-jaxws.xml的Tomcat上的JAX-WS Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!