Springboot集成Web service接口服务
1、WebService 是一种跨编程语言和跨操作系统平台的远程调用技术。
2、WebService平台的三大技术:XML+XSD,SOAP,WSDL。
1)、XML+XSD:WebService采用HTTP协议传输数据,采用XML格式封装数据(即XML中说明调用远程服务对象的哪个方法,传递的参数是什么,以及服务对象的 返回结果是什么)。XML是WebService平台中表示数据的格式。除了易于建立和易于分析外,XML主要的优点在于它既是平台无关的,又是厂商无关 的。无关性是比技术优越性更重要的:软件厂商是不会选择一个由竞争对手所发明的技术的。
2)、SOAP:WebService通过HTTP协议发送请求和接收结果时,发送的请求内容和结果内容都采用XML格式封装,并增加了一些特定的HTTP消息头,以说明 HTTP消息的内容格式,这些特定的HTTP消息头和XML内容格式就是SOAP协议。SOAP提供了标准的RPC方法来调用Web Service。SOAP协议 = HTTP协议 + XML数据格式
。
3)、WSDL:WebService也一样,WebService客户端要调用一个WebService服务,首先要有知道这个服务的地址在哪,以及这个服务里有什么方 法可以调用,所以,WebService务器端首先要通过一个WSDL文件来说明自己家里有啥服务可以对外调用,服务是什么(服务中有哪些方法,方法接受 的参数是什么,返回值是什么),服务的网络地址用哪个url地址表示,服务通过什么方式来调用。WSDL(Web Services Description Language)就是这样一个基于XML的语言,用于描述Web Service及其函数、参数和返回值。它是WebService客户端和服务器端都 能理解的标准格式。因为是基于XML的,所以WSDL既是机器可阅读的,又是人可阅读的,这将是一个很大的好处。一些最新的开发工具既能根据你的 Web service生成WSDL文档,又能导入WSDL文档,生成调用相应WebService的代理类代码。
3、这里使用的是maven依赖,修改pom.xml配置文件,如下所示:
说明:这里使用springboot2.1.3或者2.2.4.RELEASE都可以,更高版本未测试。
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 5 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 6 <modelVersion>4.0.0</modelVersion> 7 <parent> 8 <groupId>org.springframework.boot</groupId> 9 <artifactId>spring-boot-starter-parent</artifactId> 10 <version>2.1.3.RELEASE</version> 11 <relativePath /> <!-- lookup parent from repository --> 12 </parent> 13 <groupId>com.example</groupId> 14 <artifactId>demo</artifactId> 15 <version>0.0.1-SNAPSHOT</version> 16 <name>demo</name> 17 <description>Demo project for Spring Boot</description> 18 19 <properties> 20 <java.version>1.8</java.version> 21 <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version> 22 </properties> 23 24 <dependencies> 25 <dependency> 26 <groupId>org.springframework.boot</groupId> 27 <artifactId>spring-boot-starter-web</artifactId> 28 </dependency> 29 30 <dependency> 31 <groupId>org.springframework.boot</groupId> 32 <artifactId>spring-boot-starter-test</artifactId> 33 <scope>test</scope> 34 <exclusions> 35 <exclusion> 36 <groupId>org.junit.vintage</groupId> 37 <artifactId>junit-vintage-engine</artifactId> 38 </exclusion> 39 </exclusions> 40 </dependency> 41 42 <!-- webservice技术,cxf是apache封装的webservice技术的框架 --> 43 <dependency> 44 <groupId>org.apache.cxf</groupId> 45 <artifactId>cxf-spring-boot-starter-jaxws</artifactId> 46 <version>3.2.5</version> 47 </dependency> 48 <dependency> 49 <groupId>org.springframework.boot</groupId> 50 <artifactId>spring-boot-starter-web-services</artifactId> 51 </dependency> 52 </dependencies> 53 54 <build> 55 <plugins> 56 <plugin> 57 <groupId>org.springframework.boot</groupId> 58 <artifactId>spring-boot-maven-plugin</artifactId> 59 </plugin> 60 </plugins> 61 <resources> 62 <resource> 63 <directory>src/main/resources</directory> 64 <includes> 65 <include>**/*.properties</include> 66 <include>**/*.yml</include> 67 <include>**/*.xml</include> 68 <include>**/*.p12</include> 69 <include>**/*.html</include> 70 <include>**/*.jpg</include> 71 <include>**/*.png</include> 72 </includes> 73 </resource> 74 </resources> 75 </build> 76 77 </project>
创建一个实体类,用户信息的返回和封装,如下所示:
1 package com.demo.po; 2 3 import java.io.Serializable; 4 5 public class UserInfo implements Serializable { 6 7 /** 8 * 9 */ 10 private static final long serialVersionUID = 1L; 11 12 private Integer userId;// 用户编号 13 14 private String userAccount;// 用户账号 15 16 private String userPw;// 用户密码 17 18 private String userName;// 用户姓名 19 20 private Integer userAge;// 用户年龄 21 22 private String userSex;// 用户性别 23 24 public Integer getUserId() { 25 return userId; 26 } 27 28 public void setUserId(Integer userId) { 29 this.userId = userId; 30 } 31 32 public String getUserAccount() { 33 return userAccount; 34 } 35 36 public void setUserAccount(String userAccount) { 37 this.userAccount = userAccount; 38 } 39 40 public String getUserPw() { 41 return userPw; 42 } 43 44 public void setUserPw(String userPw) { 45 this.userPw = userPw; 46 } 47 48 public String getUserName() { 49 return userName; 50 } 51 52 public void setUserName(String userName) { 53 this.userName = userName; 54 } 55 56 public Integer getUserAge() { 57 return userAge; 58 } 59 60 public void setUserAge(Integer userAge) { 61 this.userAge = userAge; 62 } 63 64 public String getUserSex() { 65 return userSex; 66 } 67 68 public void setUserSex(String userSex) { 69 this.userSex = userSex; 70 } 71 72 @Override 73 public String toString() { 74 return "UserInfo [userId=" + userId + ", userAccount=" + userAccount + ", userPw=" + userPw + ", userName=" 75 + userName + ", userAge=" + userAge + ", userSex=" + userSex + "]"; 76 } 77 78 79 }
定义Webservice接口,接口需要注解@WebService注解和@WebMethod注解的,如下所示:
1 package com.demo.service; 2 3 import javax.jws.WebMethod; 4 import javax.jws.WebParam; 5 import javax.jws.WebService; 6 7 /** 8 * 9 * @author 10 * 11 */ 12 @WebService // 定义接口为一个webservice服务,定义服务,在类上边,作用在具体类上 13 public interface UserInfoWebService { 14 15 /** 16 * 定义方法为一个webservice方法 17 * 18 * @WebParam-定义参数,在方法参数前边,用于定义wsdl中的参数映射,定制单个参数到web service消息部分和xml元素的映射关系 19 * 20 * @param userId 21 * @return 22 */ 23 @WebMethod // 定义方法,在公开方法上边,此注解用在方法上,用于修改对外暴漏的方法,定制返回值到wsdl部分和xml元素的映射关系 24 public String getUserInfo(@WebParam(name = "userId") String userId); 25 26 }
定义接口实现类:targetNamespace 的值最好是包名反写,endpointInterface 是webservice接口的地址,这里参数配置也可以使用自动生成的,看个人需求的,注意这里我配置之后报错了(说明:是因为我配置错误,报的错,但是不影响SoapUI工具调用,但是客户端访问就报错了,这里进行说明一下),所以去掉自定义配置了,让其自动生成了。
注意给这个类添加@Component直接注入到spring中,或者在配置类中注入bean的方式进行注入到容器中,如下所示:
1 package com.demo.service.impl; 2 3 import javax.jws.WebService; 4 5 import com.demo.po.UserInfo; 6 import com.demo.service.UserInfoWebService; 7 8 /** 9 * 10 * @author 11 * 12 */ 13 // @WebService( 14 // targetNamespace = "http://impl.service.demo.com/", 15 // endpointInterface = "com.demo.service.impl.UserInfoWebServiceImpl") 16 @WebService 17 public class UserInfoWebServiceImpl implements UserInfoWebService { 18 19 @Override 20 public UserInfo getUserInfo(Integer userId) { 21 System.out.println("---------------------------------userId--------------------------- : " + userId); 22 UserInfo userInfo = new UserInfo(); 23 userInfo.setUserId(userId); 24 userInfo.setUserAccount("张姗姗"); 25 userInfo.setUserPw("123456"); 26 userInfo.setUserAge(26); 27 userInfo.setUserSex("男"); 28 userInfo.setUserName("张姗姗"); 29 return userInfo; 30 } 31 32 }
定义Web service接口服务的配置类:该类的作用是将改Web service服务以userInfoWebService的名称发布出去,如下所示:
1 package com.demo.config; 2 3 import javax.xml.ws.Endpoint; 4 5 import org.apache.cxf.Bus; 6 import org.apache.cxf.bus.spring.SpringBus; 7 import org.apache.cxf.jaxws.EndpointImpl; 8 import org.apache.cxf.transport.servlet.CXFServlet; 9 import org.springframework.boot.web.servlet.ServletRegistrationBean; 10 import org.springframework.context.annotation.Bean; 11 import org.springframework.context.annotation.Configuration; 12 13 import com.demo.service.UserInfoWebService; 14 import com.demo.service.impl.UserInfoWebServiceImpl; 15 16 /** 17 * 18 * @author 19 * 20 */ 21 @Configuration 22 public class WebServiceConfig { 23 24 @Bean(name = "cxfServlet") // 注入servlet bean name不能dispatcherServlet ,否则会覆盖dispatcherServlet 25 public ServletRegistrationBean<CXFServlet> cxfServlet() { 26 return new ServletRegistrationBean<CXFServlet>(new CXFServlet(), "/webservice/*"); 27 } 28 29 @Bean 30 public UserInfoWebService userInfoWebService() { 31 return new UserInfoWebServiceImpl(); 32 } 33 34 @Bean(name = Bus.DEFAULT_BUS_ID) 35 public SpringBus springBus() { 36 return new SpringBus(); 37 } 38 39 @Bean 40 public Endpoint endpoint() { 41 // 参数二,是SEI实现类对象 42 EndpointImpl endpoint = new EndpointImpl(this.springBus(), this.userInfoWebService()); 43 // 发布服务 44 endpoint.publish("/userListService"); 45 return endpoint; 46 } 47 48 }
在浏览器输入http://localhost:8080/webservice/userListService?wsdl,如下所示:
在将Springboot和CXF集成之后,如果没有在配置类中配置ServletRegistrationBean的话,访问地址是无法获取到wsdl的稳定的,解决办法就是new ServletRegistrationBean<CXFServlet>(new CXFServlet(), "/webservice/*");注入一个bean。
使用SoapUI工具或者自己编写客户端去测试服务接口,这里先使用SoapUI工具进行测试,稍后自己编写客户端进行调用测试,如下所示:
SoapUI工具安装参考:https://www.cnblogs.com/Sweettesting/p/11399534.html,我这里使用的还是5.1.2版本,有的使用的是5.3.0版本的,界面略有不通。
SoapUI工具使用教程参考:https://blog.csdn.net/w0002399/article/details/82051404
这里可以选择使用上面的xml界面或者使用下面的表单界面都可以,看个人需求,效果如下所示:
4、如何进行客户端访问呢,简单的客户端访问,动态调用的方式,缺点是只能返回Object对象,如下所示:
1 package com.demo.utils; 2 3 import org.apache.cxf.endpoint.Client; 4 import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; 5 6 public class WebServiceClient { 7 8 public static void main(String[] args) { 9 // 代理工厂 10 JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); 11 // 接口地址,这里如果是不是本公司的,需要将wsdl下载到本地的项目中,然后引用本地的哦 12 Client client = dcf.createClient("http://localhost:8080/webservice/userListService?wsdl"); 13 // 可以在此处配置入拦截器或者出拦截器 14 // client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD)); 15 Object[] objects = new Object[0]; 16 try { 17 // invoke("方法名",参数1,参数2,参数3....); 18 // 切记invoke的第一个参数是方法的名称,第二个参数是一个可变参数 19 objects = client.invoke("getUserInfo", 1); 20 System.out.println("返回数据:" + objects[0]); 21 } catch (java.lang.Exception e) { 22 e.printStackTrace(); 23 } 24 } 25 26 }
此时,如果启动项目,会报下面的错误,解决方法就是右击项目,Properties,然后找到Java Build Path,使用jdk的环境即可,如果使用jre的环境就会报下面的错误:
1 12:22:58.036 [main] DEBUG org.apache.cxf.common.logging.LogUtils - Using org.apache.cxf.common.logging.Slf4jLogger for logging. 2 12:22:58.519 [main] DEBUG org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Creating client from WSDL http://localhost:8080/webservice/userListService?wsdl 3 12:22:58.620 [main] DEBUG org.apache.cxf.resource.DefaultResourceManager - resolving resource <org.apache.cxf.wsdl11.WSDLManagerImpl/bus> type <interface org.apache.cxf.Bus> 4 12:22:58.621 [main] DEBUG org.apache.cxf.resource.DefaultResourceManager - resolving resource <null> type <interface org.apache.cxf.Bus> 5 12:22:59.028 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been (re)configured for plain http. 6 12:22:59.030 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 7 12:22:59.030 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Auth Supplier configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 8 12:22:59.030 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been configured for plain http. 9 12:22:59.032 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - registering incoming observer: org.apache.cxf.transport.TransportURIResolver$1@2c34f934 10 12:22:59.103 [main] DEBUG org.apache.cxf.transport.http.Headers - Accept: */* 11 12:22:59.104 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'. An affirmative Trust Decision is assumed. 12 12:22:59.390 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been (re)configured for plain http. 13 12:22:59.390 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 14 12:22:59.391 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Auth Supplier configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 15 12:22:59.391 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been configured for plain http. 16 12:22:59.391 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - registering incoming observer: org.apache.cxf.transport.TransportURIResolver$1@3427b02d 17 12:22:59.392 [main] DEBUG org.apache.cxf.transport.http.Headers - Accept: */* 18 12:22:59.392 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'. An affirmative Trust Decision is assumed. 19 Exception in thread "main" java.lang.IllegalStateException: Unable to create schema compiler 20 at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompilerWithDefaultAllocator(JAXBUtils.java:744) 21 at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createSchemaCompiler(DynamicClientFactory.java:445) 22 at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:325) 23 at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:243) 24 at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:236) 25 at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:191) 26 at com.demo.utils.WebServiceClient.main(WebServiceClient.java:12) 27 Caused by: javax.xml.bind.JAXBException 28 - with linked exception: 29 [java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC] 30 at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompiler(JAXBUtils.java:729) 31 at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompilerWithDefaultAllocator(JAXBUtils.java:736) 32 ... 6 more 33 Caused by: java.lang.ClassNotFoundException: com/sun/tools/internal/xjc/api/XJC 34 at java.lang.Class.forName0(Native Method) 35 at java.lang.Class.forName(Unknown Source) 36 at org.apache.cxf.common.jaxb.JAXBUtils.createSchemaCompiler(JAXBUtils.java:722) 37 ... 7 more
修改完jdk的环境之后,如果启动客户端访问,就会报下面的错误,这里就需要注意了,
1 12:39:55.490 [main] DEBUG org.apache.cxf.common.logging.LogUtils - Using org.apache.cxf.common.logging.Slf4jLogger for logging. 2 12:39:55.996 [main] DEBUG org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Creating client from WSDL http://localhost:8080/webservice/userListService?wsdl 3 12:39:56.061 [main] DEBUG org.apache.cxf.resource.DefaultResourceManager - resolving resource <org.apache.cxf.wsdl11.WSDLManagerImpl/bus> type <interface org.apache.cxf.Bus> 4 12:39:56.062 [main] DEBUG org.apache.cxf.resource.DefaultResourceManager - resolving resource <null> type <interface org.apache.cxf.Bus> 5 12:39:56.287 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been (re)configured for plain http. 6 12:39:56.288 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 7 12:39:56.289 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Auth Supplier configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 8 12:39:56.290 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been configured for plain http. 9 12:39:56.295 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - registering incoming observer: org.apache.cxf.transport.TransportURIResolver$1@3ee0fea4 10 12:39:56.333 [main] DEBUG org.apache.cxf.transport.http.Headers - Accept: */* 11 12:39:56.334 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'. An affirmative Trust Decision is assumed. 12 12:39:56.739 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been (re)configured for plain http. 13 12:39:56.740 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 14 12:39:56.740 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Auth Supplier configured for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' 15 12:39:56.740 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit' has been configured for plain http. 16 12:39:56.740 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - registering incoming observer: org.apache.cxf.transport.TransportURIResolver$1@7714e963 17 12:39:56.740 [main] DEBUG org.apache.cxf.transport.http.Headers - Accept: */* 18 12:39:56.741 [main] DEBUG org.apache.cxf.transport.http.HTTPConduit - No Trust Decider for Conduit '{http://cxf.apache.org}TransportURIResolver.http-conduit'. An affirmative Trust Decision is assumed. 19 12:39:57.403 [main] DEBUG org.apache.cxf.endpoint.dynamic.DynamicClientFactory - Created classes: com.demo.service.GetUserInfo, com.demo.service.GetUserInfoResponse, com.demo.service.ObjectFactory, com.demo.service.UserInfo 20 org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name {http://impl.service.demo.com/}getUserInfo. 21 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:331) 22 at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:325) 23 at com.demo.utils.WebServiceClient.main(WebServiceClient.java:19)
解决方案:@WebService(targetNamespace = "http://service.demo.com/", endpointInterface = "com.demo.service.impl.UserInfoWebService")。
这个注解里面targetNamespace是一定要写的,这是指名我们暴露出去的接口在哪,不写映射不到,就会报No operation was found with the name {http://impl.service.demo.com/}getUserInfo.这个错误 ,请注意targetNamespace最后面有一个斜线。endpointInterface="com.demo.service.impl.UserInfoWebService" 这个是告诉接口是那个,不配置也报错。
1 package com.demo.service.impl; 2 3 import javax.jws.WebService; 4 5 import com.demo.po.UserInfo; 6 import com.demo.service.UserInfoWebService; 7 8 /** 9 * 10 * @author 11 * 12 */ 13 @WebService( 14 targetNamespace = "http://service.demo.com/", 15 endpointInterface = "com.demo.service.UserInfoWebService") 16 // @WebService 17 public class UserInfoWebServiceImpl implements UserInfoWebService { 18 19 @Override 20 public UserInfo getUserInfo(Integer userId) { 21 System.out.println("---------------------------------userId--------------------------- : " + userId); 22 UserInfo userInfo = new UserInfo(); 23 userInfo.setUserId(userId); 24 userInfo.setUserAccount("张姗姗"); 25 userInfo.setUserPw("123456"); 26 userInfo.setUserAge(26); 27 userInfo.setUserSex("男"); 28 userInfo.setUserName("张姗姗"); 29 return userInfo; 30 } 31 32 }
5、下面使用代理类工厂的方式,获取到自己的对象,进行调用,返回自己需要的内容,如下所示:
1 package com.demo.utils; 2 3 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; 4 5 import com.demo.po.UserInfo; 6 import com.demo.service.UserInfoWebService; 7 8 public class WebServiceClient { 9 10 public static void main(String[] args) { 11 try { 12 // 接口地址 13 String address = "http://localhost:8080/webservice/userListService?wsdl"; 14 // 代理工厂 15 JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); 16 // 设置代理地址 17 jaxWsProxyFactoryBean.setAddress(address); 18 // 设置接口类型 19 jaxWsProxyFactoryBean.setServiceClass(UserInfoWebService.class); 20 // 创建一个代理接口实现 21 UserInfoWebService userInfoWebService = (UserInfoWebService) jaxWsProxyFactoryBean.create(); 22 // 数据准备 23 Integer userId = 1; 24 // 调用代理接口的方法调用并返回结果 25 UserInfo userInfo = userInfoWebService.getUserInfo(userId); 26 System.out.println("返回结果: " + userInfo); 27 } catch (Exception e) { 28 e.printStackTrace(); 29 } 30 } 31 32 }
返回结果,如下所示: