cxf+Spring的webservice应用
来源:互联网 发布:淘宝最好的外贸原单店 编辑:程序博客网 时间:2024/04/26 03:16
服务端的开发:
SEI:
package com.xh.ws.sei;import javax.jws.WebService;import com.xh.ws.bean.User;@WebServicepublic class SayHelloImpl implements SayHello {public SayHelloImpl() {super();System.out.println("調用....SayHelloImpl()");}@Overridepublic User sayHello(User u) {System.out.println("server:sayhello>>>>"+u.toString());return u;}}
bean:
package com.xh.ws.bean;import javax.xml.bind.annotation.XmlRootElement;@XmlRootElement(name = "User")public class User {private int id;private String name;private String password;public int getId() {return id;}public void setId(int id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public User(){}public User(int id,String name,String password){this.id=id;this.name=name;this.password=password;}public String toString(){return ">>>"+id+":"+name+":"+password;}}
Test:
package com.xh.ws.test;public class TestServer {public static void main(String[] args) {/** * 未用sprig之前的方法Endpoint.publish("http://127.0.0.1:34512", new SayHelloImpl());System.out.println("发布成功!"); *//** * 使用spring后,只需要部署在TOMcat就可以了 */}}
bean.xml:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="UserProcess" implementor="com.xh.ws.sei.SayHelloImpl" address="/userProcess" /></beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><display-name>hello1</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping></web-app>
客户端:
bean.xml:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"><jaxws:client id="UserClient" serviceClass="com.xh.ws.sei.SayHello" address="http://localhost:8080/ws_spring_s/userProcess" /></beans>
web.xml:
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><display-name>hello1</display-name><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:bean.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class> org.apache.cxf.transport.servlet.CXFServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
Test:
package com.xh.ws.test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import com.xh.ws.sei.SayHello;import com.xh.ws.sei.User;public class TestClient {public static void main(String[] args) {/** * 未用sprig之前的方法SayHelloImplService factory=new SayHelloImplService();System.out.println(factory.getSayHelloImplPort().sayHello("lina")); * */ApplicationContext applicationContext=new ClassPathXmlApplicationContext("classpath:bean.xml");SayHello sayHello=(SayHello) applicationContext.getBean("UserClient");User u=new User(12,"lina","123123");System.out.println(sayHello.sayHello(u).toString());}}
0 0
- cxf+Spring的webservice应用
- cxf+Spring的webservice应用--拦截器
- 4、webService CXF的应用2 Spring的配置方法
- CXF集成SPRING的WEBSERVICE
- WebService应用之CXF集成spring详解
- 谈谈WebService开发-应用篇(四)-CXF基于Spring的应用
- spring中发布基于cxf的webservice
- WebService之CXF与Spring的整合
- CXF+spring构建restful风格的webservice
- webservice 基于spring的cxf发布
- Spring+CXF开发RESTful风格的WebService
- WebService的CXF框架整合Spring
- 【JAVA】CXF+Spring上的webservice
- WebService-CXF-Spring基于web的cxf
- 力所能及之webservice CXF框架的应用
- Web应用中使用CXF不基于Spring的WebService发布
- cxf+spring发布webservice
- CXF WebService整合Spring
- java线程停止问题
- HTML <button> 标签的 type 属性
- RxJava操作符(一)Creating Observables
- 7则心理寓言故事
- [php函数]--数组函数--array_chunk
- cxf+Spring的webservice应用
- NodeJS 使用Stream 方式 copy 大文件
- 第二种方法制作三角
- 如何发布Node模块到NPM社区
- API Guides(六)—— Create a Search Interface To Drag and Drop
- 51nod--任务执行顺序
- Android 微信支付彻底扫坑
- 简述 Struts2 的工作流程:
- Android 项目目录结构