springboot整合webservice使用簡單案例總結(jié)
因為做的項目中用到了webservice,所以在此總結(jié)一下。
一、webservice簡介
Web Service也叫XML Web Service, WebService是一種可以接收從Internet或者Intranet上的其它系統(tǒng)中傳遞過來的請求,輕量級的獨立的通訊技術(shù)。是通過SOAP在Web上提供的軟件服務(wù),使用WSDL文件進行說明,并通過UDDI進行注冊。WebService是一種跨編程語言和跨操作系統(tǒng)平臺的遠(yuǎn)程調(diào)用技術(shù)。
還可以從多個角度來理解WebService,從表面看,WebService就是一個應(yīng)用程序向外界暴露出一個能通過Web進行調(diào)用的API,也就是說能用編程的方法通過Web來調(diào)用這個應(yīng)用程序。我們把調(diào)用這個WebService的應(yīng)用程序叫做客戶端,而把提供這個WebService的應(yīng)用程序叫做服務(wù)端。從深層次看,WebService是建立可互操作的分布式應(yīng)用程序的新平臺,是一個平臺,是一套標(biāo)準(zhǔn)。它定義了應(yīng)用程序如何在Web上實現(xiàn)互操作性,你可以用任何你喜歡的語言,在任何你喜歡的平臺上寫Web service ,只要我們可以通過Web service標(biāo)準(zhǔn)對這些服務(wù)進行查詢和訪問。
二、webservice三要素:
SOAP、WSDL、UDDI(UniversalDescriptionDiscovery andIntegration)三者構(gòu)成了WebService的三要素。下面詳細(xì)闡述這三大技術(shù):
SOAP:
WebService通過HTTP協(xié)議發(fā)送請求和接收結(jié)果時,發(fā)送的請求內(nèi)容和結(jié)果內(nèi)容都采用XML格式封裝,并增加了一些特定的HTTP消息頭,以說明HTTP消息的內(nèi)容格式,這些特定的HTTP消息頭和XML內(nèi)容格式就是SOAP協(xié)議。SOAP提供了標(biāo)準(zhǔn)的RPC(遠(yuǎn)程調(diào)用技術(shù))方法來調(diào)用Web Service。
SOAP協(xié)議組成:
SOAP協(xié)議 = HTTP協(xié)議 + XML數(shù)據(jù)格式
SOAP協(xié)議定義了SOAP消息的格式,SOAP協(xié)議是基于HTTP協(xié)議的,SOAP也是基于XML的,XML是SOAP的數(shù)據(jù)編碼方式。
WSDL
好比我們?nèi)ド痰曩I東西,首先要知道商店里有什么東西可買,然后再來購買,商家的做法就是張貼廣告海報。 WebService也一樣,WebService客戶端要調(diào)用一個WebService服務(wù),首先要有知道這個服務(wù)的地址在哪,以及這個服務(wù)里有什么方法可以調(diào)用,所以,WebService務(wù)器端首先要通過一個WSDL文件來說明自己家里有啥服務(wù)可以對外調(diào)用,服務(wù)是什么(服務(wù)中有哪些方法,方法接受的參數(shù)是什么,返回值是什么),服務(wù)的網(wǎng)絡(luò)地址用哪個url地址表示,服務(wù)通過什么方式來調(diào)用。
WSDL(Web Services Description Language)就是這樣一個基于XML的語言,用于描述Web Service及其函數(shù)、參數(shù)和返回值。它是WebService客戶端和服務(wù)器端都能理解的標(biāo)準(zhǔn)格式。因為是基于XML的,所以WSDL既是機器可閱讀的,又是人可閱讀的,這將是一個很大的好處。一些最新的開發(fā)工具既能根據(jù)你的Web service生成WSDL文檔,又能導(dǎo)入WSDL文檔,生成調(diào)用相應(yīng)WebService的代理類代碼。
UDDI
uddi是一個跨產(chǎn)業(yè),跨平臺的開放性架構(gòu),可以幫助 Web 服務(wù)提供商在互聯(lián)網(wǎng)上發(fā)布 Web 服務(wù)的信息。UDDI 是一種目錄服務(wù),企業(yè)可以通過 UDDI 來注冊和搜索 Web 服務(wù)。簡單來說,UDDI 就是一個目錄,只不過在這個目錄中存放的是一些關(guān)于 Web 服務(wù)的信息而已。
也就是說:
- soap:就是在與webservice通信時規(guī)定好的協(xié)議
- wsdl:就是webservice中的食譜,你可以找到webservice中有哪些材料(方法),怎去做這道菜(入?yún)?、方法、返回值)?/li>
- uddi:wsdl是食譜的話,uddi就是菜單,可以用來注冊和搜索web服務(wù)。
三、為什么要使用WebService
- 跨平臺調(diào)用
- 跨語言調(diào)用
- 遠(yuǎn)程調(diào)用
四、springboot簡單調(diào)用案例
1、引入依賴:
<!-- CXF webservice -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.4.5</version>
</dependency>2、創(chuàng)建實體類:
@Data
@Builder
public class UserDto {
private Long id;
private String name;
private Integer age;
private String address;
}3、創(chuàng)建WebService接口
public interface IUserServer {
UserDto getUser(Long str);
}4、創(chuàng)建WebService接口的實現(xiàn)類
@Service
@WebService
public class UserServerImpl implements IUserServer {
@Override
public UserDto getUser(Long id) {
return UserDto.builder()
.id(id)
.address("上海市浦東新區(qū)")
.age(25)
.name("laJi").build();
}
}這里用到了注解@WebService,我這就只在實現(xiàn)類上使用了。這里介紹一下,先來看下它的定義:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface WebService {
String name() default "";
String targetNamespace() default "";
String serviceName() default "";
String portName() default "";
String wsdlLocation() default "";
String endpointInterface() default "";
}name: 對應(yīng)wsdl:portType標(biāo)簽,默認(rèn)值為Java類或接口的名稱;
targetNamespace: 命名空間,一般寫為接口的包名倒序,默認(rèn)值也是接口的包名倒序。對應(yīng)wsd:definitions:targetNamespace 標(biāo)簽;
serviceName: WebService的服務(wù)名稱,對應(yīng)wsdl:service,默認(rèn)值為WebService接口實現(xiàn)類的名稱+“Service”,示例:UserServiceImplServicce
portName: 對應(yīng)wsdl:port標(biāo)簽,默認(rèn)值為:WebService接口實現(xiàn)類的名稱+“Port”,示例:UserServiceImplPort
wsdlLocation: 指定用于定義WebService的WSDL文檔的地址
endpoointInterfacce: WebService接口全路徑
5、創(chuàng)建WebService配置類
@Configuration
@RequiredArgsConstructor
public class CxfConfig {
private final IUserServer userServer;
/**
* 注入Servlet,注意beanName不能為dispatcherServlet
* @author Fang Ruichuan
* @date 2022/11/14 19:16
*/
@Bean
public ServletRegistrationBean cxfServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), userServer);
endpoint.publish("/api");
return endpoint;
}
}進行訪問:http://localhost:8080/webservice

然后點擊url

客戶端:
public class WebserviceClient {
public static void main(String[] args) {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8080/webservice/api?wsdl");
final ObjectMapper mapper = new ObjectMapper();
try {
Object[] objects = client.invoke("getUser", 99L);
System.out.println(mapper.writeValueAsString(objects[0]));
} catch (Exception e) {
e.printStackTrace();;
}
}
}顯示:
{"address":"上海市浦東新區(qū)","age":25,"id":99,"name":"laJi"}五、進階使用:
webservice的服務(wù)端是以遠(yuǎn)程接口為主的,在java實現(xiàn)的webService主要是依靠的是CXF開發(fā)框架,而這個CXF框架可以直接將接口發(fā)布成webservice,同時還要考慮到整個項目之中的安全性問題。
相關(guān)注解:
1)@WebService
1、serviceName: 對外發(fā)布的服務(wù)名,指定 Web Service 的服務(wù)名稱:wsdl:service。缺省值為 Java 類的簡單名稱 + Service。(字符串)
2、endpointInterface: 服務(wù)接口全路徑, 指定做SEI(Service EndPoint Interface)服務(wù)端點接口,包名+實現(xiàn)類的接口的完整路徑
3、name:此屬性的值包含XML Web Service的名稱。在默認(rèn)情況下,該值是實現(xiàn)XML Web Service的類的名稱,wsdl:portType 的名稱。缺省值為 Java 類的簡單名稱 + Service。(字符串)
4、portName: wsdl:portName。缺省值為 WebService.name+Port。
5、targetNamespace:指定你想要的名稱空間,默認(rèn)是使用接口實現(xiàn)類的包名的反綴
6、wsdlLocation:指定用于定義 Web Service 的 WSDL 文檔的 Web 地址。Web 地址可以是相對路徑或絕對路徑。(字符串)
注意:實現(xiàn)類上可以不添加Webservice注解
2)@WebMethod
注釋表示作為一項 Web Service 操作的方法,將此注釋應(yīng)用于客戶機或服務(wù)器服務(wù)端點接口(SEI)上的方法,或者應(yīng)用于 JavaBeans 端點的服務(wù)器端點實現(xiàn)類。
要點: 僅支持在使用 @WebService 注釋來注釋的類上使用 @WebMethod 注釋
1、operationName:指定與此方法相匹配的wsdl:operation 的名稱。缺省值為 Java 方法的名稱。(字符串)
2、action:定義此操作的行為。對于 SOAP 綁定,此值將確定 SOAPAction 頭的值。缺省值為 Java 方法的名稱。(字符串)
3、exclude:指定是否從 Web Service 中排除某一方法。缺省值為 false。(布爾值)
3)@Oneway
注釋將一個方法表示為只有輸入消息而沒有輸出消息的 Web Service 單向操作。
將此注釋應(yīng)用于客戶機或服務(wù)器服務(wù)端點接口(SEI)上的方法,或者應(yīng)用于 JavaBeans 端點的服務(wù)器端點實現(xiàn)類
4)@WebParam
注釋用于定制從單個參數(shù)至 Web Service 消息部件和 XML 元素的映射。
將此注釋應(yīng)用于客戶機或服務(wù)器服務(wù)端點接口(SEI)上的方法,或者應(yīng)用于 JavaBeans 端點的服務(wù)器端點實現(xiàn)類。
1、name :參數(shù)的名稱。如果操作是遠(yuǎn)程過程調(diào)用(RPC)類型并且未指定partName 屬性,那么這是用于表示參數(shù)的 wsdl:part 屬性的名稱。如果操作是文檔類型或者參數(shù)映射至某個頭,那么 -name 是用于表示該參數(shù)的 XML 元素的局部名稱。如果操作是文檔類型、參數(shù)類型為 BARE 并且方式為 OUT 或 INOUT,那么必須指定此屬性。(字符串)
2、partName:定義用于表示此參數(shù)的 wsdl:part屬性的名稱。僅當(dāng)操作類型為 RPC 或者操作是文檔類型并且參數(shù)類型為BARE 時才使用此參數(shù)。(字符串)
3、targetNamespace:指定參數(shù)的 XML 元素的 XML 名稱空間。當(dāng)屬性映射至 XML 元素時,僅應(yīng)用于文檔綁定。缺省值為 Web Service 的targetNamespace。(字符串)
4、mode:此值表示此方法的參數(shù)流的方向。有效值為 IN、INOUT 和 OUT。(字符串)
5、header:指定參數(shù)是在消息頭還是消息體中。缺省值為 false。(布爾值)
5)@WebResult
注釋用于定制從返回值至 WSDL 部件或 XML 元素的映射。將此注釋應(yīng)用于客戶機或服務(wù)器服務(wù)端點接口(SEI)上的方法,或者應(yīng)用于 JavaBeans 端點的服務(wù)器端點實現(xiàn)類。
1、name:當(dāng)返回值列示在 WSDL 文件中并且在連接上的消息中找到該返回值時,指定該返回值的名稱。對于 RPC 綁定,這是用于表示返回值的 wsdl:part屬性的名稱。對于文檔綁定,-name參數(shù)是用于表示返回值的 XML 元素的局部名。對于 RPC 和 DOCUMENT/WRAPPED 綁定,缺省值為 return。對于 DOCUMENT/BARE 綁定,缺省值為方法名 + Response。(字符串)
2、targetNamespace:指定返回值的 XML 名稱空間。僅當(dāng)操作類型為 RPC 或者操作是文檔類型并且參數(shù)類型為 BARE 時才使用此參數(shù)。(字符串)
3、header:指定頭中是否附帶結(jié)果。缺省值為false。(布爾值)
4、partName:指定 RPC 或 DOCUMENT/BARE 操作的結(jié)果的部件名稱。缺省值為@WebResult.name。(字符串)
6)@HandlerChain
注釋用于使 Web Service 與外部定義的處理程序鏈相關(guān)聯(lián)。只能通過對 SEI 或?qū)崿F(xiàn)類使用 @HandlerChain 注釋來配置服務(wù)器端的處理程序。
但是可以使用多種方法來配置客戶端的處理程序。可以通過對生成的服務(wù)類或者 SEI 使用 @HandlerChain 注釋來配置客戶端的處理程序。此外,可以按程序在服務(wù)上注冊您自己的 HandlerResolver 接口實現(xiàn),或者按程序在綁定對象上設(shè)置處理程序鏈。
1、file:指定處理程序鏈文件所在的位置。文件位置可以是采用外部格式的絕對 java.net.URL,也可以是類文件中的相對路徑。(字符串)
2、name:指定配置文件中處理程序鏈的名稱。
/** * WebService涉及到的有這些 "四解三類 ", 即四個注解,三個類 * @WebMethod * @WebService * @WebResult * @WebParam * SpringBus * Endpoint * EndpointImpl * * 一般我們都會寫一個接口,然后再寫一個實現(xiàn)接口的實現(xiàn)類,但是這不是強制性的 * @WebService 注解表明是一個webservice服務(wù)。 * name:對外發(fā)布的服務(wù)名, 對應(yīng)于<wsdl:portType name="ServerServiceDemo"></wsdl:portType> * targetNamespace:命名空間,一般是接口的包名倒序, 實現(xiàn)類與接口類的這個配置一定要一致這種錯誤 * Exception in thread "main" org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name xxxx * 對應(yīng)于targetNamespace="http://server.webservice.example.com" * endpointInterface:服務(wù)接口全路徑(如果是沒有接口,直接寫實現(xiàn)類的,該屬性不用配置), 指定做SEI(Service EndPoint Interface)服務(wù)端點接口 * serviceName:對應(yīng)于<wsdl:service name="ServerServiceDemoImplService"></wsdl:service> * portName:對應(yīng)于<wsdl:port binding="tns:ServerServiceDemoImplServiceSoapBinding" name="ServerServiceDemoPort"></wsdl:port> * * @WebMethod 表示暴露的服務(wù)方法, 這里有接口ServerServiceDemo存在,在接口方法已加上@WebMethod, 所以在實現(xiàn)類中不用再加上,否則就要加上 * operationName: 接口的方法名 * action: 沒發(fā)現(xiàn)又什么用處 * exclude: 默認(rèn)是false, 用于阻止將某一繼承方法公開為web服務(wù) * * @WebResult 表示方法的返回值 * name:返回值的名稱 * partName: * targetNamespace: * header: 默認(rèn)是false, 是否將參數(shù)放到頭信息中,用于保護參數(shù),默認(rèn)在body中 * * @WebParam * name:接口的參數(shù) * partName: * targetNamespace: * header: 默認(rèn)是false, 是否將參數(shù)放到頭信息中,用于保護參數(shù),默認(rèn)在body中 * model:WebParam.Mode.IN/OUT/INOUT */
使用步驟:
1)創(chuàng)建接口:
@WebService(name = "UserSSSS" ,targetNamespace ="http://data.fucker.mother.com")
public interface UserService {
User getUser(String userName);
}2)創(chuàng)建實現(xiàn)類:
@Service
@WebService(name = "UserSSSS" ,
targetNamespace ="http://data.fucker.mother.com",
endpointInterface = "com.mother.fucker.data.service.UserService")
public class UserServerImpl implements UserService {
@Override
@WebMethod(operationName = "getUser")
@WebResult(name = "User")
public User getUser(@WebParam(name = "userName") String userName) {
return new User("姓名","年齡","性別","工作");
}
}3)創(chuàng)建身份認(rèn)證攔截器:(不需要可以不創(chuàng)建)
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.springframework.stereotype.Component;
import org.w3c.dom.NodeList;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPHeader;
import javax.xml.soap.SOAPMessage;
@Component
@Slf4j
public class WebServiceAuthInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
/**
* 用戶名
*/
private static final String USER_NAME = "wangdi";
/**
* 密碼
*/
private static final String USER_PASSWORD = "wangdi.com";
private static final String NAME_SPACE_URI = "http://data.fucker.mother.com";
/**
* 創(chuàng)建攔截器
*/
private SAAJInInterceptor interceptor = new SAAJInInterceptor();
public WebServiceAuthInterceptor() {
super(Phase.PRE_PROTOCOL);
//添加攔截
super.getAfter().add(SAAJInInterceptor.class.getName());
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
//獲取指定消息
SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
if (null == soapMessage) {
this.interceptor.handleMessage(message);
soapMessage = message.getContent(SOAPMessage.class);
}
//SOAP頭信息
SOAPHeader header = null;
try {
header = soapMessage.getSOAPHeader();
} catch (SOAPException e) {
e.printStackTrace();
}
if (null == header) {
throw new Fault(new IllegalAccessException("沒有Header信息,無法實現(xiàn)用戶認(rèn)證處理!"));
}
//SOAP是基于XML文件結(jié)構(gòu)進行傳輸?shù)?,所以如果要想獲取認(rèn)證信息就必須進行相關(guān)的結(jié)構(gòu)約定
NodeList usernameNodeList = header.getElementsByTagNameNS(NAME_SPACE_URI, "username");
NodeList passwordNodeList = header.getElementsByTagNameNS(NAME_SPACE_URI, "password");
if (usernameNodeList.getLength() < 1) {
throw new Fault(new IllegalAccessException("沒有用戶信息,無法實現(xiàn)用戶認(rèn)證處理!"));
}
if (passwordNodeList.getLength() < 1) {
throw new Fault(new IllegalAccessException("沒有密碼信息,無法實現(xiàn)用戶認(rèn)證處理!"));
}
String username = usernameNodeList.item(0).getTextContent().trim();
String password = passwordNodeList.item(0).getTextContent().trim();
if (USER_NAME.equals(username) && USER_PASSWORD.equals(password)) {
log.info("用戶訪問認(rèn)證成功!");
} else {
SOAPException soapException = new SOAPException("用戶認(rèn)證失敗!");
log.info("用戶認(rèn)證失敗!");
throw new Fault(soapException);
}
}
}
4)創(chuàng)建配置類:
import com.mother.fucker.data.AuthInterceptor.WebServiceAuthInterceptor;
import com.mother.fucker.data.service.UserService;
import lombok.RequiredArgsConstructor;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
@Configuration
@RequiredArgsConstructor
public class CxfConfig {
private final UserService userServer;
@Autowired
private WebServiceAuthInterceptor interceptor;
/**
* 注入Servlet,注意beanName不能為dispatcherServlet
* @author Fang Ruichuan
* @date 2022/11/14 19:16
*/
@Bean
public ServletRegistrationBean cxfServlet() {
return new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), userServer);
endpoint.publish("/api");
endpoint.getInInterceptors().add(this.interceptor);
return endpoint;
}
/*用于發(fā)布多個WebService*/
// @Bean
// public Endpoint messageEndPoint2() {
// EndpointImpl endpoint = new EndpointImpl(springBus(), this.ageInfoService);
// endpoint.publish("/userInfoService");
endpoint.getInInterceptors().add(this.interceptor);
// return endpoint;
// }
}5)創(chuàng)建客戶端攔截器:(如有需要)
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.headers.Header;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import java.util.List;
public class ClientLoginInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
private String username;
private String password;
private static final String NAME_SPACE_URI = "http://data.fucker.mother.com";
public ClientLoginInterceptor(String username, String password) {
super(Phase.PREPARE_SEND);
this.username = username;
this.password = password;
}
@Override
public void handleMessage(SoapMessage soapMessage) throws Fault {
List<Header> headers = soapMessage.getHeaders();
Document document = DOMUtils.createDocument();
Element authority = document.createElementNS(NAME_SPACE_URI, "authority");
Element username = document.createElementNS(NAME_SPACE_URI, "username");
Element password = document.createElementNS(NAME_SPACE_URI, "password");
username.setTextContent(this.username);
password.setTextContent(this.password);
authority.appendChild(username);
authority.appendChild(password);
headers.add(0, new Header(new QName("authority"), authority));
}
}6) 新建客戶端調(diào)用接口(使用動態(tài)代理)
/**
* 用戶名
*/
private static final String USER_NAME = "wangdi";
/**
* 密碼
*/
private static final String USER_PASSWORD = "wangdi.com";
private static final String NAME_SPACE_URI = "http://server.webservice.gtp.sinotrans.com";
public static void main(String[] args) {
//打印日志
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
List<Logger> loggerList = loggerContext.getLoggerList();
loggerList.forEach(logger -> {logger.setLevel(Level.INFO); });
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:8001/webservice/api?wsdl");
try {
client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME, USER_PASSWORD));
Object[] objects = client.invoke("getUser","aaa");
System.out.println(JSON.toJSONString(objects[0]));
} catch (Exception e) {
e.printStackTrace();;
}
}7)當(dāng)webservcie中參數(shù)是復(fù)雜類型的是:
@Override
@WebMethod(operationName = "getUser")
public User getUser(@WebParam(name = "userName") User userName) {
return new User("姓名","年齡","性別","工作");
}
需要這樣調(diào)用:
//打印日志
// LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
// List<Logger> loggerList = loggerContext.getLoggerList();
// loggerList.forEach(logger -> {logger.setLevel(Level.INFO); });
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://localhost:1001/webservice/api?wsdl");
try {
//通過反射,創(chuàng)建OrderInfo對象,com.limp.service.OrderInfo 這個包名稱必須和webservice的中的order路徑一致
Object user = Thread.currentThread().getContextClassLoader().
loadClass("com.mother.fucker.data.User").newInstance();
//初始化實體對象
Method m = user.getClass().getMethod("setName", String.class);
m.invoke(user, "uuid213-281heq-2131");
Object[] objects = client.invoke("getUser",user);
System.out.println(JSON.toJSONString(objects[0]));
} catch (Exception e) {
e.printStackTrace();;
}總結(jié)
到此這篇關(guān)于springboot整合webservice使用的文章就介紹到這了,更多相關(guān)springboot整合webservice內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Spring boot webService使用方法解析
- SpringBoot調(diào)用第三方WebService接口的操作技巧(.wsdl與.asmx類型)
- SpringBoot整合WebService的實現(xiàn)示例
- SpringBoot創(chuàng)建WebService方法詳解
- SpringBoot調(diào)用第三方WebService接口的兩種方法
- SpringBoot調(diào)用對方webService接口的幾種方法示例
- SpringBoot整合WebService的實戰(zhàn)案例
- Java(Springboot)項目調(diào)用第三方WebService接口實現(xiàn)代碼
相關(guān)文章
一篇文章了解Jackson注解@JsonFormat及失效解決辦法
這篇文章主要給大家介紹了關(guān)于如何通過一篇文章了解Jackson注解@JsonFormat及失效解決辦法的相關(guān)資料,@JsonFormat注解是一個時間格式化注解,用于格式化時間,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11
徹底解決Spring mvc中時間的轉(zhuǎn)換和序列化等問題
這篇文章主要介紹了徹底解決Spring mvc中時間的轉(zhuǎn)換和序列化等問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
Java中LinkedHashSet的實現(xiàn)原理詳解
這篇文章主要介紹了Java中LinkedHasSet的實現(xiàn)原理詳解,LinkedHashSet?是具有可預(yù)知迭代順序的?Set?接口的哈希表和鏈接列表實現(xiàn),此實現(xiàn)與HashSet?的不同之處在于,后者維護著一個運行于所有條目的雙重鏈接列表,需要的朋友可以參考下2023-09-09
Spring Boot整合JPA使用多個數(shù)據(jù)源的方法步驟
這篇文章主要給大家介紹了關(guān)于Spring Boot整合JPA使用多個數(shù)據(jù)源的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
SpringSecurity多認(rèn)證器配置多模式登錄自定義認(rèn)證器方式
這篇文章主要介紹了SpringSecurity多認(rèn)證器配置多模式登錄自定義認(rèn)證器方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-04-04
短網(wǎng)址的原理與生成方法(Java實現(xiàn))
這篇文章主要給大家介紹了關(guān)于短網(wǎng)址的原理與生成方法,利用的是Java實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10

