WebService整合Spring
发布时间:2020-12-16 23:33:58 所属栏目:安全 来源:网络整理
导读:WebService with Spring? 一:创建服务器端 1.1:web.xml 配置 ? ? !-- ? 配置Spring的ContextLoaderListener监听器-- ? context-param ? ? param-namecontextConfigLocation/param-name ? ? param-value/WEB-INF/classes/cxf-servlet.xml/param-value ? /co
WebService with Spring?
一:创建服务器端
1.1:web.xml 配置
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
1.2:代码编写
1.2.1//编写接口
package demo.cxf.service;
import javax.jws.WebService;
@WebService(注释一定要写)
public interface Login {
public String login(String name,String password);
}
2.2.2//实现接口方法
package demo.cxf.service;
import javax.jws.WebService;
@WebService(endpointInterface="demo.cxf.service.Login",serviceName="Login")(注释一定要写)
public class LoginImpl implements Login {
@Override
public String login(String name,String password) {
String result = "登陆CXF服务端成功!";
if(!"cxf".equalsIgnoreCase(name)||
!"cxf".equalsIgnoreCase(password)){
result = "用户名或密码不正确,请重新登陆!";
}
return result;
}
}
1.3:编写Spring配置文件 ?
<?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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
</beans>
1.4:启动服务器 ?
?
?
?
?
?
?
?
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import demo.cxf.service.Login;
public class CXFClient {
public static void main(String[] args) {
JaxWsProxyFactoryBean jwpFactory = new JaxWsProxyFactoryBean();
jwpFactory.setAddress("http://localhost:8088/mycxf/Login?wsdl");
jwpFactory.setServiceClass(Login.class);
Login login = (Login)jwpFactory.create();
String result = login.login("cxf","cxf");
System.out.println("登陆结果:"+result);
}
}?
2.3:需要Spring管理的(web.xml不要在配置CXF启动啦)
2.3.1 配置Spring配置文件(客户端配置有2种方法)
?
<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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
</beans>
?
?
import org.springframework.context.support.ClassPathXmlApplicationC
import demo.cxf.service.Login;
import demo.spring.service.HelloWorld;
public class Client {
public static void main(String[] args) {
ClassPathXmlApplicationC
?
Login client = (Login)context.getBean("helloClient");
String response = client.login("cxf","cxf");
System.out.println("Response:"+response);
System.exit(0);
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- twitter-bootstrap – 导入引导少于扩展类在字形字体上创建
- scala – Future [期权[期货[期权[布尔]]简化期货和期权?
- Shell编程面试题5_实现判断10.0.0.0/24网络里,当前在线用户
- AngularJS修改model值时,显示内容不变
- 使用AngularJS(Java Config)上传Spring Rest Multipart文件
- angularjs – Ui-Router $state.go()不刷新数据
- WebService学习笔记-读取webxml.com.cn的天气服务信息
- RESTful 的webservice
- 如何在shell函数中获得效果并使用“set -e”? [重复]
- Angular 2:单击元素时检查shift键是否关闭