spring cxf webservice的客户端代码

前面文章已经把server端代码和wsdl注册到spring的代码都有了,这里开始写spring soap的client。这里就很简单了,只用引入项目就可以使用了 。代码在spring-soap-https-soap-client

pom

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <!--引入 -->
    <dependency>
        <groupId>com.springboot</groupId>
        <artifactId>spring-soap-https-soap-intergration</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

main class添加@Enable注解 @EnableCountryEndpointApi

@SpringBootApplication
@EnableConfigurationProperties
@EnableAutoConfiguration
@EnableCountryEndpointApi
public class SslClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(SslClientApplication.class, args);
    }

}

业务代码

@RestController
public class CountryController {

    @Autowired
    private CountryEndpoint countryEndpoint;

    @GetMapping(path = "/country/{name}")
    public CountryInfo getCountryInfo(@PathVariable("name") String name){
        CountryByNameRequest req = new CountryByNameRequest();
        req.setName(name);
        CountryResponse rsp = countryEndpoint.getCountryByName(req);
        return new CountryInfo(rsp);
    }
}
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
慷慨打赏