我正在遵循Spring指南来创建Web服务的客户端。首先,我创建服务器,但是没有问题。我生成了一个jar并执行了它。它返回响应。
这些是我的专长:
InventoryClient.java
public class InventoryClient extends WebServiceGatewaySupport {
public CatalogResponse getCatalog(Catalog cataog) {
Catalog request = new Catalog();
CatalogResponse response = (CatalogResponse) getWebServiceTemplate()
.marshalSendAndReceive("http://localhost:8080/ws/", request,
new SoapActionCallback(
"http://com.uciext.ws.hw5/Catalog"));
return response;
}
}
InventoryConfiguration.java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@Configuration
public class InventoryConfiguration {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage> specified in
// pom.xml
marshaller.setContextPath("inventory.wsdl");
return marshaller;
}
@Bean
public InventoryClient getCatalog(Jaxb2Marshaller marshaller) {
InventoryClient client = new InventoryClient();
client.setDefaultUri("http://localhost:8080/ws");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
Application.java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
Util.log("---- Application: args[1] "+args[0]);
}
@Bean
void lookup(InventoryClient inventoryClient) {
Catalog catalog = new Catalog();
CatalogResponse response = inventoryClient.getCatalog(catalog);
Util.log("---- Application: date"+response.getReturn().getLastModifiedDate());
}
}
执行jar时,出现以下错误
Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: Provider com.sun.xml.internal.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "inventory.wsdl" doesnt contain ObjectFactory.class or jaxb.index
- with linked exception:
[javax.xml.bind.JAXBException: "inventory.wsdl" doesnt contain ObjectFactory.class or jaxb.index]
当我创建服务器时,我是从stock.xsd生成类的。
答案 0 :(得分:0)
尝试直接在Java包下制作jaxb创建的wsdl包