本文介绍了Java如何初始化JAXB / JAX-WS / etc实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图理解Java如何在JRE中包含标准参考实现(例如JRE6中的JAXB / JAX-WS),同时仍允许第三方实现覆盖(例如CXF) 。

I'm just digging around a bit trying to understand how Java can have standard reference implementations included in the JRE (eg JAXB/JAX-WS in JRE6), while still allowing 3rd-party implementations to override that (eg CXF).

我找到了找到javax.xml.ws.spi.FactoryFinder.find()方法的地方,该方法可以找到META中指定的类。 INF / services / java.xml.ws.spi.Provider或com.sun.xml.internal.ws.spi.ProviderImpl(对于JAX-WS案例)并创建一个实例。

I've gotten to the place that I found the javax.xml.ws.spi.FactoryFinder.find() method which either locates the class specified in META-INF/services/java.xml.ws.spi.Provider or com.sun.xml.internal.ws.spi.ProviderImpl (for the JAX-WS case) and creates an instance of that.

我找不到的是JRE调用FactoryFinder.find()方法的阶段/在哪里/哪个阶段。

What I can't find is how/where/at which stage the JRE calls that FactoryFinder.find() method.

任何人都可以启发我?

我找到了答案,但我不允许自己发布另外3个小时......

[edit] I've found the answer but am not allowed to post it myself for another 3 hours...

推荐答案

想出完整的逻辑。实际上JVM启动时没有任何反应。这一切都基于延迟加载,例如真正的JAX-WS /任何提供者只在第一次需要时加载/实例化。

Figured out the complete logic. Actually nothing happens on JVM startup. It's all based on lazy loading, eg the real JAX-WS/whatever provider is only loaded/instantiated the first time it's needed.

在加载JAX-的情况下WS实施:

In the case of loading the JAX-WS implementation:

假设我们想要呼叫一个网络服务,使用如下代码:

Assume we want to call a web service, using code like:

MyService     service = new MyService_Service();
MyServiceSoap port    = service.getMyServiceSoap();

port.mymethod();

然后初始化JAX-WS实现会发生以下情况:

then the following happens to initialize the JAX-WS implementation:


  • 任何JAX-WS Web服务都扩展了javax.xml.ws.Service,因此MyService_Service扩展了服务

  • 当您创建Web实例时service,它的超类(javax.xml.ws.Service)也被初始化(构造函数)

  • Service的构造函数调用javax.xml.ws.spi.Provider.provider() ,这是一个静态方法,它使用javax.xml.ws.spi.FactoryFinder.find()来查找和实例化已配置的实现。

假设我们希望使用以下代码发布 Web服务:

Assume we want to publish a web service using code like:

@WebService(endpointInterface = "my.package.MyService")
public class MyServiceImp implements MyService {
    ...
}

MyServiceImp      service  = new MyServiceImp();
InetSocketAddress addr     = new InetSocketAddress(8080);
Executor          executor = Executors.newFixedThreadPool(16);
HttpServer        server   = new HttpServer(addr);
server.setExecutor(executor);

HttpContext       context  = server.createContext("/MyService");
Endpoint          endpoint = Endpoint.create(service);
endpoint.publish(context);
server.start();

然后初始化JAX-WS实现会发生以下情况:

then the following happens to initialize the JAX-WS implementation:


  • Endpoint.create()运行Provider.provider()。createEndpoint()

  • Provider.provider()是一个使用的静态方法javax.xml.ws.spi.FactoryFinder.find()用于查找并实例化已配置的实现。

以下链接帮助我理解:





  • (除了研究由Apache CXF的wsdl2java生成的源文件外)

  • http://kickjava.com/src/javax/xml/ws/Service.java.htm
  • http://kickjava.com/src/javax/xml/ws/spi/Provider.java.htm
  • http://kickjava.com/src/javax/xml/ws/Endpoint.java.htm
  • (in addition to studying the source files as generated by wsdl2java from Apache CXF)

这篇关于Java如何初始化JAXB / JAX-WS / etc实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:29