使用cxf开发webservice服务

 

 

依赖

 1 <!-- webservice 依赖包 这个包很重要,如果缺失的话会出现各种奇怪的异常,不是未找到类哦! -->
 2 <dependency>
 3     <groupId>org.apache.cxf</groupId>
 4     <artifactId>cxf-rt-frontend-jaxws</artifactId>
 5     <version>3.1.6</version>
 6 </dependency>
 7 <dependency>
 8     <groupId>org.apache.cxf</groupId>
 9     <artifactId>cxf-rt-transports-http</artifactId>
10     <version>3.1.6</version>
11 </dependency>
12 <dependency>
13     <groupId>com.vaadin.external.google</groupId>
14     <artifactId>android-json</artifactId>
15     <version>0.0.20131108.vaadin1</version>
16     <scope>compile</scope>
17 </dependency>
18 <dependency>
19     <groupId>wsdl4j</groupId>
20     <artifactId>wsdl4j</artifactId>
21     <version>1.6.3</version>
22 </dependency>
23 <dependency>
24     <groupId>org.apache.cxf</groupId>
25     <artifactId>cxf-rt-transports-http-jetty</artifactId>
26     <version>3.2.4</version>
27 </dependency>
28 <!--解析xml报文-->
29 <dependency>
30     <groupId>dom4j</groupId>
31     <artifactId>dom4j</artifactId>
32     <version>1.6.1</version>
33 </dependency>

接口

 1 package com.example.demo;
 2 
 3 import org.springframework.stereotype.Service;
 4 
 5 @Service
 6 public interface HelloService {
 7 
 8     public  String sayHello(String content);
 9 
10     public  String sayHello1(String content);
11 }

实现类

 1 package com.example.demo;
 2 
 3 import org.springframework.stereotype.Service;
 4 import javax.jws.WebService;
 5 
 6 @WebService
 7 @Service
 8 public class HelloServiceImpl implements HelloService {
 9     @Override
10     public String sayHello(String content){
11         return content;
12     }
13 
14     @Override
15     public String sayHello1(String content) {
16         return content;
17     }
18 }

Config

 1 package com.example.demo;
 2 
 3 import org.springframework.beans.factory.annotation.Autowired;
 4 import org.springframework.boot.ApplicationArguments;
 5 import org.springframework.boot.ApplicationRunner;
 6 import org.springframework.stereotype.Component;
 7 import org.springframework.stereotype.Service;
 8 
 9 import javax.xml.ws.Endpoint;
10 
11 @Component
12 @SuppressWarnings("all")
13 @Service
14 public class CxfConfig implements ApplicationRunner {
15 
16     @Autowired
17     HelloService helloService;
18 
19     @Override
20     public void run(ApplicationArguments args) throws Exception {
21         Endpoint.publish("http://10.0.24.7:8081/CXFwebserviceTestInfterface", helloService);
22         System.out.println("webservice接口 发布成功");
23     }
24 }

主类(默认)

 1 package com.example.demo;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 
 6 @SpringBootApplication
 7 public class DemoApplication {
 8     public static void main(String[] args) {
 9         SpringApplication.run(DemoApplication.class, args);
10     }
11 }

启动

 

 

 

 

SoapUI测试

 

posted @ 2022-08-10 22:26  勤快的懒羊羊  阅读(216)  评论(0编辑  收藏  举报