问题
I have multiple (let's say 2, A and B) webservices and I need to generate a client to use them togheter. In Netbeans I use the wizard "new Web Service Client" passing the two wsdl, looking at the output Netbeans simply call wsimport for each of them.
wsimport http:/mydomain/wsA.svc?wsdl
wsimport http:/mydomain/wsB.svc?wsdl
Both A and B, generate a the same package com.mydomain.myapp (I guess they are defined in the same namespace), so I get the stub class set of A and B merged in the same package.
However, wsimport also creates an ObjectFactory for each webservice so if I generate the stub of B after A I obtain only the ObjectFactory related to B definitions (because the first, A, is overwritten). Conversely, ObjectFactory of A survives if I switch the order.
The problem is that I need both ObjectFactories in order to create the JAXBElements wrapping clas instances for the types of both webservices A and B.
Is there a way to map the namespace for A in a java package and the B in another one in order to obtain
com.mydomain.myapp.a
com.mydomain.myapp.b
and so keep both ObjectFactories ?
Simple refactoring is not helping because internally a getClass() is called so, once a package has been refactored it does not work anymore.
回答1:
You can probably do this via JAXB binding files - have a look at this question/answer: java wsimport rename/different ObjectFactory.java
From that answer, have a look at the binding file stuff at oracle: http://docs.oracle.com/javaee/5/tutorial/doc/bnbbf.html
回答2:
This worked for me (using Spring java config)
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setPackagesToScan("com.example.api");
return marshaller;
}
Using setPackagesToScan
instead of setContextPath
did the work for me (I assume it ignores what's in ObjectFactory
and scans the whole package).
来源:https://stackoverflow.com/questions/15783166/wsimport-multiple-wsdl-overwrite-objectfactory