How does Java initialize the JAXB / Jax WS / etc implementation?
I just want to know how Java includes standard reference implementations (such as JAXB / jax-ws in jre6) in JRE, while still allowing third-party implementations to override it (such as CXF)
I found javax xml. ws. spi. FactoryFinder. Find () method, which can find meta inf / services / Java xml. ws. spi. Class specified in provider or com sun. xml. internal. ws. spi. Providerimpl (for Jax - WS cases) and create an instance
What I can't find is that JRE calls factoryfinder The time / location / stage of the find () method
Can anyone enlighten me?
[editor] I found the answer, but I don't allow myself to publish for another three hours
Solution
Find out the complete logic In fact, there is no response when the JVM starts It's all based on deferred loading, such as real Jax - WS / any provider that loads / instantiates only the first time it's needed
When loading the jax-ws implementation:
Suppose we want to call the web service with the following code:
MyService service = new MyService_Service(); MyServiceSoap port = service.getMyServiceSoap(); port.mymethod();
Then, the jax-ws implementation is initialized with the following events:
>Any jax-ws web service extends javax xml. ws. Service, so myservice_ Service extends service > when you create an instance of a web service, its superclass (javax. XML. WS. Service) will also be initialized (constructor) > "service" constructor calls javax xml. ws. spi. Provider. Provider (), which is a static method that uses javax xml. ws. spi. FactoryFinder. Find () to find and instantiate the implemented implementation
Suppose we want to publish a web service using the following code:
@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();
Then, the jax-ws implementation is initialized with the following events:
> Endpoint. Create() runs provider provider(). createEndpoint() > Provider. Provider () is a static method that uses javax xml. ws. spi. FactoryFinder. Find () to find and instantiate the configured implementation
The following links help me understand this:
> 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 generated by wsdl2java of Apache CXF)