CXF简单整合Springmvc

SpringMVC整合cxf webservice出现提示No service was found解决办法 2019独角兽企业重金招聘Python工程师标准>>> ... 阅读详情

首先配置spring加载配置文件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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xsi:schemaLocation="  
    http://www.springframework.org/schema/beans   
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    ">
    
    <context:component-scan base-package="com.axb.cheney" />
	
</beans>

接着配置springmvc配置文件spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

	<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
	<context:component-scan base-package="com.axb.cheney" />

	<!-- 自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 
		两个bean, 是spring MVC为@Controllers分发请求所必须的。 -->
	<mvc:annotation-driven />

	<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
	<bean id="mappingJacksonHttpMessageConverter"
		class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
	</bean>

	<!-- 国际化拦截器 -->
	<mvc:interceptors>
		<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
	</mvc:interceptors>
	<bean id="messageSource"
		class="org.springframework.context.support.ResourceBundleMessageSource">
		<property name="basename" value="messages" />
		<property name="defaultEncoding" value="UTF-8" />
		<property name="useCodeAsDefaultMessage" value="true" />
	</bean>

	<!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
	<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<ref bean="mappingJacksonHttpMessageConverter" />
				<bean class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/plain;charset=UTF-8</value>
						</list>
					</property>
				</bean>
			</list>
		</property>
	</bean>

	<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
		p:prefix="/" p:suffix=".jsp" />

</beans>

下面是写的一个接口和对应的实现类:

接口类

package com.axb.cheney.server;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface AutheCentral {
	
	public String VerifySessionToken(String sessionToken);

}

接口实现类

package com.axb.cheney.serverImpl;

import javax.jws.WebService;

@WebService(endpointInterface="com.axb.cheney.server.AutheCentral") 
public class AutheCentralImpl implements AutheCentral {
    @Override
	public String VerifySessionToken(String sessionToken) {
        return sessionToken;
    }

}

配置cxf-servert.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:soap="http://cxf.apache.org/bindings/soap"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/bindings/soap 
    http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
	
	<!-- 配置方式1 注意:serviceClass为接口类并非实现类 -->
	<!-- http://localhost:8090/hyteraWS/services/autheCentral?wsdl -->
	<jaxws:server id="autheCentral" serviceClass="com.axb.cheney.server.AutheCentral"
		address="/autheCentral">
		<jaxws:serviceBean>  
        <bean class="com.axb.cheney.serverImpl.AutheCentralImpl" />  
    	</jaxws:serviceBean>  
	</jaxws:server>
	
</beans>

配置web.xml:

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	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>mybatis</display-name>
	<!-- 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml. 读两个节点: <listener></listener> 
		和 <context-param></context-param> -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml,
        		 classpath:cxf-servlet.xml,
        		 classpath:spring-mvc.xml
    </param-value>
	</context-param>

	<!-- 过滤 -->
	<filter>
		<description>字符集过滤器</description>
		<filter-name>encodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<description>字符集编码</description>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>encodingFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<!-- 监听 -->
	<listener>
		<description>spring监听器</description>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<listener>
		<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
	</listener>

	<!-- servlet -->
	<servlet>
		<servlet-name>springMvc</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<description>spring mvc 配置文件</description>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:spring-mvc.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>springMvc</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>

	<servlet>
		<servlet-name>CXFService</servlet-name>
		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>CXFService</servlet-name>
		<url-pattern>/services/*</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>


</web-app>

启动服务,查看发布接口成功:

通过浏览器访问发布的接口,输入http://localhost:8090/hyteraWS/services/autheCentral?wsdl

 

2、编写客户端,测试发布接口,最简单方式就是通过工具自动生成调用代码,以Eclipse为例

点击finish,生成工程,如下

编写简单测试类,并调用接口方法

package com.axb.cheney.test;

import java.rmi.RemoteException;

import com.axb.cheney.server.AutheCentralProxy;

public class Test {

	public static void main(String[] args) throws RemoteException {
		AutheCentralProxy proxy = new AutheCentralProxy();
		String str = proxy.verifySessionToken("hello CXF");
		System.out.println("response:"+str);
	}

}

返回结果:

嗯嗯,好像很简单的样子,喝喝喝。。。

springMVC整合cxf所需的jar包 立即下载

相关推荐

maven 搭建springMVC+cxf+mybatis整合项目

maven 搭建springMVC+cxf+mybatis整合项目

SpringMvc整合cxf

springMvc整合cxf发布webService接口服务示例

csithero的博客 424

springmvc整合cxf webservice

NULL 博文链接:https://lafecat.iteye.com/blog/2283186

springmvc集成cxf

springmvc中继承cxf 利用cxf发布webService接口以及调用cxf接口分两步:第一步:服务端的发布;1:配置web.xml文件,添加cxf的servlet &lt;servlet&gt; &lt;servlet-name&gt;cxf&lt;/servlet-name&gt; &lt;servlet-class&gt;org.apache.c...

白不懂黑的静的专栏 2455

springMvc项目集成cxf实现webService通信方式的详细步骤

Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intranet上的其它系统中传递过来的请求,轻量级的独立的通讯技术。是:通过SOAP在Web上提供的软件服务,使用WSDL文件进行说明,并通过UDDI进行注册。 XML:(Extensible Markup Language)扩展型可标记语言。面向短期的临时数据处理、面向万维网络,是Soap的基础。 Soap:(Simple Object Access P

跟着飞哥学编程(全栈联盟) 1962

springMVC集成webservice服务cxf的实现步骤

一、前期准备工作: 1、所需要的 jar包:jar包地址 2、下载wsdl2java所需要的文件:比如目录结构:D:\test; 下载地址:文件下载 3、wsdl2java命令配置环境变量,在path中配置D:\test\bin(即指定到步骤2中文件bin); 二、新增spring-webservice.xml文件,添加如下内容: 添加对外发布的server,以及声明server名称。(

qq_35702591的博客 2161

Maven项目SpringMvc集成CXF实现WebService接口

开发Webservice接口可以使用Axis2,也可以使用CXF。可以参考下面几篇博客(主要讲述Axis2开发Webservice接口): Axis2在eclipse中搭建 在Eclipse中使用Axis2插件生成Web Service服务端/客户端 Axis2与Web项目整合及Axis2在Web项目中整合Spring 利用AXIS2开发Webservice接口,浏览器访问返回纯JSON数...

崔向阳@李晓的博客 1751

cxf spring 服务端客户端开发

1.在原有springmvc上面添加cxf服务端: maven添加依赖: 新建cxf的接口类与实现类,接口类HelloWorld HelloWorld{ String(Stringtext)} 实现类 (=) HelloWorldImplHelloWorld{ ...

chongxieyue6738的博客 137

Apache-CXF整合SpringMVC WebService Apache-CXF整合SpringMVC

Apache-CXF整合SpringMVC WebService Apache-CXF整合SpringMVC 一、前言 1、最近公司一个项目,突然需要用到WebService,网上找了下,实现的方式很多,这里记录下Apache-CXFSpringMVC整合过程。 2、SpringMVC 部分配置略, CXF单独也可以在web项目中运行。 二、WebService 服务端 代码实现 1、依赖pom <!-- https://mvnrepository.com/artif...

HaHa_Sir的博客 1040

SpringMVC整合cxf发布webservices服务【留档】

SpringMVC整合cxf发布webservices服务【留档】 记SpringMVC整合cxf发布webservices服务【留档】 网络查询的发现大部分有遗漏不全,或不可用。整合多个后才成功,在这留个档记录下。 1.所需jar包 :jar包链接 也可以网上找 2、代码 添加 接口: 接口实现类 3、配置 修改web.xml文件,在末尾增加配置<servlet> &lt...

u013092399的博客 418

5分钟带你入门CXFSpringMVC 整合

1.准备cxf的jar包如果没有的话可以访问,链接:http://pan.baidu.com/s/1pLPpruV 密码:u13r2.在web.xml中配置cxf-servlet.xml <!-- CXF和servlet整合 走一下源码就知道它会找cxf-servlet.xml文件--> <servlet> <servlet-name>cxf</servlet-name>

甲凹I饕餮的博客 1131

spring整合CXF开发webService接口所需的全部jar包

花费了1天整理的jar包,spring的版本较低,但是可以用。

SpringMVC+Hibernate3+CXF整合详细实例

上传的文件是springMVC框架整合Hibernate3和CXF的系统,里面有关于springMVC利用cxf发布webservice和调用接口的详细代码,后台用annotation注解关联数据库,dao层完美封装,架构层次分明,用不到cxf的可以到这个链接免费下载springMVC+hibernate3的实例代码(http://download.csdn.net/detail/shzy1988/9393870)

CXF +SpringMvc 生成服务端

下载apache cxf 文件配置相关JDK 生成 model_cxf.wsdl模板文件,拷贝至D:\apache-cxf\bin 目录下 命令cmd窗口切换至cxf文件存在的目录如 D:\apache-cxf\bin 执行``wsdl2java -impl -server -p com.demo model_cxf.wsdl` 拷贝生成的代码至maven项目工程中 pox.xml 配置lib ...

路人甲的博客 238

CXF整合springspringmvc

CXFspringspringmvc整合,调用网络服务 整合springspringmvc所需jar包 <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}&l

m0_50726623的博客 287

CXF简单配置应用

Server: //1.创建发布服务的工厂 JaxWsServerFactoryBean factoryBean=new JaxWsServerFactoryBean(); //2.设置服务地址 factoryBean.setAddress("http://localhost:8888/book"); //3.设置服务接...

过去过去,未来未来,当下永恒! 815

CXFSpring MVC的整合

CXFSpring MVC的整合  一.开发环境:  JDK:1.7     CXF:apache-cxf-3.0.9 , cxf:可以到http://cxf.apache.org/download.html下载  Spring: 3.2.4  二. CXF的jar包问题: CXF的jar包有很多,其中很多都是用不到的,我开发的必备的jar包如下图:     apache-

申公的专栏 3343

Spring整合CXF发布Web Services

Spring的Web项目搭建不再描述,主要介绍Web项目整合CXF发布Web Services 1.导入CXF需要的jar包 cxf-2.7.2.jar httpasyncclient-4.0-beta3.jar httpclient-4.2.1.jar httpcore-4.2.2.jar httpcore-nio-4.2.2.jar neethi-3.0.2.jar wsd

jclpc的专栏 606
上一篇: eclipse报错之Context root cannot be empty
Cheney1993
博客等级 码龄11年 13粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值