同样,这里是使用Maven及Java8
同样Maven添加如下依赖:
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>3.0.8.RELEASE</version>
</dependency>
添加plugin用于把wsdl生成为pojo类:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.example.demo.wsdl</generatePackage>
<schemas>
<schema>
<url>http://127.0.0.1:8080/ws/countries.wsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
这里的url指向wsdl的地址。
generatePackage为target生成的地方。
会进行自动生成:
下面说明下这个类!
CountryClient.java:创建Web Service服务端需要extend的WebServiceGateWaySupport。
CountryConfiguration.java:配置Country。
DemoApplication.java
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
CommandLineRunner lookup(CountryClient quoteClient) {
return args -> {
String country = "Spain";
if (args.length > 0) {
country = args[0];
}
GetCountryResponse response = quoteClient.getCountry(country);
System.err.println(response.getCountry().getCapital());
};
}
}
程序运行截图如下:
源码打包下载地址:
https://github.com/fengfanchen/Java/tree/master/SOAPWebConsume