【发布时间】:2018-11-02 15:05:24
【问题描述】:
我正在按照 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]
当我创建服务器时,我从 inventory.xsd 生成了类
【问题讨论】:
-
类路径中有inventory.wsdl吗?如果可用,请使用 new ClassPathResource("inventory.wsdl")
标签: spring web-services client