Apache Cxf WebService整合Spring(1)
来源:互联网 发布:mac口红a17是什么颜色 编辑:程序博客网 时间:2024/05/20 18:40
Apache Cxf WebService整合Spring(1)
分类: WebService2013-11-03 15:59 76人阅读 评论(0) 收藏 举报
1:步骤
(1)复制CXF的JAR包;
(2)在web.xml配置CXF的核心控制器(CXFServlet);
(3)在Spring配置文件中导入CXF的Schema和XML配置文件;
(4)在Spring配置文件中使用jaxws:endponit元素标签来暴露Web Service;
(5)如果要添加拦截器:在jaxws:endponit元素标签里添加
inInterceptors、outInterceptors子元素
2:CXF和spring整合,我准备如下jar包文件:
3:我的项目结构:
4:代码
- package com.lzw.springcxf.model;
- public class ClubModel {
- private Integer clubId;
- private String clubName;
- private String country;
- public ClubModel() {
- super();
- }
- public ClubModel(Integer clubId, String clubName, String country) {
- super();
- this.clubId = clubId;
- this.clubName = clubName;
- this.country = country;
- }
- public Integer getClubId() {
- return clubId;
- }
- public void setClubId(Integer clubId) {
- this.clubId = clubId;
- }
- public String getClubName() {
- return clubName;
- }
- public void setClubName(String clubName) {
- this.clubName = clubName;
- }
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((clubId == null) ? 0 : clubId.hashCode());
- result = prime * result + ((clubName == null) ? 0 : clubName.hashCode());
- result = prime * result + ((country == null) ? 0 : country.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ClubModel other = (ClubModel) obj;
- if (clubId == null) {
- if (other.clubId != null)
- return false;
- } else if (!clubId.equals(other.clubId))
- return false;
- if (clubName == null) {
- if (other.clubName != null)
- return false;
- } else if (!clubName.equals(other.clubName))
- return false;
- if (country == null) {
- if (other.country != null)
- return false;
- } else if (!country.equals(other.country))
- return false;
- return true;
- }
- }
- package com.lzw.springcxf.model;
- public class ClubModel {
- private Integer clubId;
- private String clubName;
- private String country;
- public ClubModel() {
- super();
- }
- public ClubModel(Integer clubId, String clubName, String country) {
- super();
- this.clubId = clubId;
- this.clubName = clubName;
- this.country = country;
- }
- public Integer getClubId() {
- return clubId;
- }
- public void setClubId(Integer clubId) {
- this.clubId = clubId;
- }
- public String getClubName() {
- return clubName;
- }
- public void setClubName(String clubName) {
- this.clubName = clubName;
- }
- public String getCountry() {
- return country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((clubId == null) ? 0 : clubId.hashCode());
- result = prime * result + ((clubName == null) ? 0 : clubName.hashCode());
- result = prime * result + ((country == null) ? 0 : country.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ClubModel other = (ClubModel) obj;
- if (clubId == null) {
- if (other.clubId != null)
- return false;
- } else if (!clubId.equals(other.clubId))
- return false;
- if (clubName == null) {
- if (other.clubName != null)
- return false;
- } else if (!clubName.equals(other.clubName))
- return false;
- if (country == null) {
- if (other.country != null)
- return false;
- } else if (!country.equals(other.country))
- return false;
- return true;
- }
- }
- package com.lzw.springcxf.service;
- import java.util.List;
- import com.lzw.springcxf.model.ClubModel;
- import com.lzw.springcxf.model.PlayerModel;
- public interface ClubService {
- public List<PlayerModel> getPlayerByClub(ClubModel Club);
- }
- package com.lzw.springcxf.service;
- import java.util.List;
- import javax.jws.WebService;
- import com.lzw.springcxf.model.ClubModel;
- import com.lzw.springcxf.model.PlayerModel;
- @WebService
- public interface HandleService {
- public String sayName(String name);
- public List<PlayerModel> getPlayerByClub(ClubModel Club);
- }
- package com.lzw.springcxf.service.impl;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import com.lzw.springcxf.model.ClubModel;
- import com.lzw.springcxf.model.PlayerModel;
- import com.lzw.springcxf.service.ClubService;
- public class ClubServiceImpl implements ClubService {
- static Map<ClubModel, List<PlayerModel>> initData = new HashMap<ClubModel, List<PlayerModel>>();
- static {
- List<PlayerModel> playA = new ArrayList<PlayerModel>();
- playA.add(new PlayerModel(1, "梅西", "10", "前锋"));
- playA.add(new PlayerModel(2, "内马尔", "11", "前锋"));
- initData.put(new ClubModel(1111, "巴塞罗那", "西班牙"), playA);
- List<PlayerModel> playB = new ArrayList<PlayerModel>();
- playB.add(new PlayerModel(3, "C罗", "7", "前锋"));
- playB.add(new PlayerModel(4, "贝尔", "11", "中场"));
- initData.put(new ClubModel(2222, "皇家马德里", "西班牙"), playB);
- }
- @Override
- public List<PlayerModel> getPlayerByClub(ClubModel Club) {
- return initData.get(Club);
- }
- }
- package com.lzw.springcxf.service.impl;
- import java.util.List;
- import javax.jws.WebService;
- import com.lzw.springcxf.model.ClubModel;
- import com.lzw.springcxf.model.PlayerModel;
- import com.lzw.springcxf.service.ClubService;
- import com.lzw.springcxf.service.HandleService;
- @WebService(endpointInterface="com.lzw.springcxf.service.HandleService", serviceName="handleServiceTest")
- public class HandleServiceImpl implements HandleService {
- private ClubService clubService;
- public void setClubService(ClubService clubService) {
- this.clubService = clubService;
- }
- @Override
- public String sayName(String name) {
- return "本次西班牙国家德比的最佳球员是:" + name;
- }
- @Override
- public List<PlayerModel> getPlayerByClub(ClubModel Club) {
- return clubService.getPlayerByClub(Club);
- }
- }
5:配置文件
(1)applicationContext.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:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:jaxws="http://cxf.apache.org/jaxws"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
- http://cxf.apache.org/jaxws
- http://cxf.apache.org/schemas/jaxws.xsd"
- default-lazy-init="true">
- <import resource="classpath:META-INF/cxf/cxf.xml"/>
- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
- <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
- <bean id="clubService" class="com.lzw.springcxf.service.impl.ClubServiceImpl">
- </bean>
- <bean id="handleService" class="com.lzw.springcxf.service.impl.HandleServiceImpl">
- <property name="clubService">
- <ref bean="clubService"/>
- </property>
- </bean>
- <jaxws:endpoint
- implementor="#handleService"
- address="/cxf">
- </jaxws:endpoint>
- </beans>
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- id="WebApp_ID" version="3.0">
- <display-name>Spring-Cxf-Demo</display-name>
- <!--定义Spring的配置的位置,可以定义多个配置文件,可以使用通配符。 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>/WEB-INF/applicationContext.xml</param-value>
- </context-param>
- <!--设置一起动当前的Web应用,就加载Spring,让Spring管理Bean -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <servlet>
- <servlet-name>cxf</servlet-name>
- <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>cxf</servlet-name>
- <url-pattern>/lzw/*</url-pattern>
- </servlet-mapping>
- </web-app>
0 0
- Apache Cxf WebService整合Spring(1)
- Apache Cxf WebService整合Spring(1)
- Apache Cxf WebService整合Spring(2)
- Apache Cxf WebService整合Spring(2)
- CXF Webservice 6 - Spring 3 整合Apache CXF WebService
- webservice快速入门-使用spring整合apache-cxf(五)
- webservice快速入门-使用spring整合apache-cxf(五)
- Spring 3 整合Apache CXF WebService
- Spring 3 整合Apache CXF WebService
- Spring 整合 Apache CXF发布webService
- Spring 3 整合Apache CXF WebService
- Spring 3 整合Apache CXF WebService
- Spring 3 整合Apache CXF WebService
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- 转:C/C++:memmove、memcpy、strcpy三者的区别
- memmove函数的使用方法
- 复制当前目录及其子目录下面的所有的txt文件,如果有文件名相同则重命名为bak01,bak02 ......
- 使用 Apache CXF 实现 Web Service 详解
- CXF整合spring
- Apache Cxf WebService整合Spring(1)
- Apache Cxf WebService整合Spring(2)
- cxf小实例
- Apache CXF 客户端调用 超时设置
- 用js来刷新当夜页面,保留参数
- Linux下python默认版本设置
- arch下ibus选择
- 大数据下Sql优化心得记录
- Node中的模块机制