java 如何配置@HandlerChain 以指向 JAR 文件中的处理程序链配置文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7908726/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:56:51  来源:igfitidea点击:

How to configure @HandlerChain to point to a handler chain configuration file inside a JAR file?

javaweb-servicesjax-ws

提问by Joaquim Oliveira

Is there a way to reference a handler configuration file (e.g.: handler.xml) that is distributed inside a JAR file?

有没有办法引用分布在 JAR 文件中的处理程序配置文件(例如:handler.xml)?

Something like this: @HandlerChain(file="somefile.jar")or @HandlerChain(file="myhandler.xml"), assuming that myhandler.xmlis stored in somefile.jar.

像这样:@HandlerChain(file="somefile.jar")或者@HandlerChain(file="myhandler.xml"),假设它myhandler.xml存储在somefile.jar.

回答by Gonzalo Garcia Lasurtegui

For both server and client implementations of handlers using the @HandlerChain annotation, you must specify the location of the handler configuration as either a relative path from the annotated file or as an absolute URL. For example:

@HandlerChain(file="../../common/handlers/myhandlers.xml")

or

@HandlerChain(file="http://foo.com/myhandlers.xml")

对于使用@HandlerChain 注释的处理程序的服务器和客户端实现,您必须将处理程序配置的位置指定为注释文件的相对路径或绝对 URL。例如:

@HandlerChain(file="../../common/handlers/myhandlers.xml")

或者

@HandlerChain(file="http://foo.com/myhandlers.xml")

Taken from thisdoc.

取自这个文档。

回答by Vinod Cyriac

handler-chain.xml file must be inside the same classpath or same jar. You need to specify the actual location of xml to load.

handler-chain.xml 文件必须在同一个类路径或同一个 jar 中。您需要指定要加载的 xml 的实际位置。

回答by Vasudev

If there is no tight dependency on configuration file, you can skip it alltogether and handle everything in the code itself.

如果对配置文件没有严格的依赖,您可以完全跳过它并在代码本身中处理所有内容。

List<Handler> handlerChain = new ArrayList<>();
handlerChain.add(new MyHandler());
((BindingProvider) port).getBinding().setHandlerChain(handlerChain);