java1234小峰推荐书籍_java1234 webservice 第2 课 cfx实现
一.新建server的maven項目
2. pox.xml文件添加jar包
org.apache.cxf
cxf-core
3.1.5
org.apache.cxf
cxf-rt-frontend-jaxws
3.1.5
org.apache.cxf
cxf-rt-transports-http-jetty
3.1.5
3. ?主方法: 然后啟動服務
package com.java1234.webservice.impl;
import javax.xml.ws.Endpoint;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
import com.java1234.webservice.HelloWorld;
public class Server {
public static void main(String[] args) {
System.out.println("web service start");
HelloWorld implementor=new HelloWorldImpl();
String address="http://192.168.244.1/helloWorld";
// Endpoint.publish(address, implementor); // jdk實現 暴露webservice接口
JaxWsServerFactoryBean factoryBean=new JaxWsServerFactoryBean();
factoryBean.setAddress(address); // 設置暴露地址
factoryBean.setServiceClass(HelloWorld.class); // 接口類
factoryBean.setServiceBean(implementor); // 設置實現類
factoryBean.create(); // 創建webservice接口
System.out.println("web service started");
}
}
二.新建ws_Client
2. 下載文件?apache-cxf-3.1.5.zip,并且解壓
新建一個文件夾:
運行命令如下:
F:\apache-cxf-3.1.5\bin\wsdl2java ?http://192.168.244.1/helloWorld?wsdl
會生成樹結構文件: 如下
3.編寫client.java
package com.java1234.webservice;
import java.util.List;
public class Client {
public static void main(String[] args) {
HelloWorldService service=new HelloWorldService();
HelloWorld helloWorld=service.getHelloWorldPort();
System.out.println(helloWorld.say("java1234_小峰"));
User user=new User();
user.setUserName("java1234");
user.setPassword("123456");
List roleList=helloWorld.getRoleByUser(user);
for(Role role:roleList){
System.out.println(role.getId()+","+role.getRoleName());
}
}
}
程序運行結果:
Hello:java1234_小峰
1,技術總監
2,架構師
總結
以上是生活随笔為你收集整理的java1234小峰推荐书籍_java1234 webservice 第2 课 cfx实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拉稀的原因(拉肚子的这些原因)
- 下一篇: 吃石榴要不要吐籽 石榴是吃汁水还是肉