一、案例

<?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_2_5.xsd"
id="WebApp_ID" version="2.5"> <!-- Spring配置文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <!-- Spring监听器 -->
<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>
</servlet> <servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping> </web-app>
  •   配置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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://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" /> <!-- 自动扫描 -->
<context:component-scan base-package="com.shyroke.service" /> <jaxws:endpoint implementor="#loginService" address="/loginService">
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
<bean class="com.shyroke.interceptor.MyLoginInteceptor"></bean>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"></bean>
</jaxws:outInterceptors>
</jaxws:endpoint>
</beans>
  • 橙色加注的代码为该webservice服务设置in和out拦截器。
  • <bean class="com.shyroke.interceptor.MyLoginInteceptor"></bean> 中MyLoginInteceptor是自定义拦截器,class的值为该自定义拦截器的所在包加类名
  • 最后启动jetty或者其他服务器即可生效。

(八)CXF之用spring添加拦截器的更多相关文章

  1. WebService -- Java 实现之 CXF ( 使用Spring添加拦截器)

    最重要的就是在ApplicationContext.xml下面添加配置 <!-- service provider --> <jaxws:endpoint implementor=& ...

  2. spring boot 添加拦截器

    构建一个spring boot项目. 添加拦截器需要添加一个configuration @Configuration @ComponentScan(basePackageClasses = Appli ...

  3. spring boot 添加拦截器的简单实例(springBoot 2.x版本,添加拦截器,静态资源不可访问解决方法)

    spring中拦截器主要分两种,一个是HandlerInterceptor,一个是MethodInterceptor 一.HandlerInterceptor HandlerInterceptor是s ...

  4. (七)CXF添加拦截器

    今天开始讲下拦截器,前面大家学过servlet,struts2 都有拦截器概念,主要作用是做一些权限过滤,编码处理等: webservice也可以加上拦截器,我们可以给webservice请求加权限判 ...

  5. 使用CXF为webservice添加拦截器

      拦截器分为Service端和Client端 拦截器是在发送soap消息包的某一个时机拦截soap消息包,对soap消息包的数据进行分析或处理.分为CXF自带的拦截器和自定义的拦截器 1.Servi ...

  6. CXF添加拦截器和自定义拦截器

    前面讲了如何采用CXF开发webservice,现在来讲如何添加拦截器和自定义拦截器. 服务端代码: HelloWorld implementor=new HelloWorldImpl(); Stri ...

  7. (五)CXF之添加拦截器

    一.需求分析 webService中的拦截器类似于servlet的Filter过滤器.一般用于调用服务前后先调用拦截器的方法. 二.案例 本章案例是基于上一章节的基础上添加拦截器的 2.1 服务端添加 ...

  8. 九、 Spring Boot 拦截器

    过滤器属于Servlet范畴的API,与spring 没什么关系. Web开发中,我们除了使用 Filter 来过滤请web求外,还可以使用Spring提供的HandlerInterceptor(拦截 ...

  9. spring boot拦截器WebMvcConfigurerAdapter,以及高版本的替换方案(转)

    文章转自 http://blog.51cto.com/12066352/2093750 最近项目采用spring icloud,用的spring boot版本是1.5.x的,spring boot 2 ...

随机推荐

  1. My algorithmic road

    序言 初窥门径 1 第一题 素数的烦恼 离开了家乡,你到达了数字之地,在这里数字2总感觉自己是自然数中最独特的一个,他只有一和它本身两个因数,为此它十分苦恼.为了不再寂寞,他建立了素数王国,他请求许多 ...

  2. python: 关于解决'\u'开头的字符串转中文的方法

    爬虫爬到的内容是这样的: 如果直接打印出来是这样的: python3的解决办法:字符串.encode('utf-8').decode('unicode_escape') python2:字符串.dec ...

  3. Fiddler is not capturing web request from Firefox

    Fiddler is not capturing web request from Firefox You can also get the FiddlerHook plug in for Firef ...

  4. oracle利用触发器实现将ddl操作存入数据表中

    先创建DDL数据库事件操作表: create table ddl_event( sys_time date primary key, event_name ), ), obj_type ), obj_ ...

  5. 关于Selenium remote模式分布式执行UI自动化测试必定面临的性能问题

    1.大部分自动化测试人员都是在本地执行UI自动化测试,也就是代码和浏览器必须在同一台机器上,这样的的缺陷很多,无法多任务并发执行UI自动化测试用例,效率极低 2.正是如此,Selenium 的remo ...

  6. 为何有DAO与Service层?为何先搞Dao接口在搞DaoImpl实现?直接用不行吗?

    转自 http://blog.sina.com.cn/s/blog_4b1452dd0102wvox.html 我们都知道有了Hibernate后,单独对数据的POJO封装以及XML文件要耗损掉一个类 ...

  7. js 如何让两个等长的数组产生键值对关系

    问题的准确描述:js 将两个长度一样的一维数组 合成一个一维数组,A为键值,B为key值 js 将两个长度一样的一维数组 合成一个一维数组,A为键值,B为key值 如 var arr1=['a','b ...

  8. Levenberg-Marquardt迭代(LM算法)-改进Guass-Newton法

                  1.前言                                a.对于工程问题,一般描述为:从一些测量值(观测量)x 中估计参数 p?即x = f(p),     ...

  9. windows服务器入门 安装配置IIS和ASP

    本人以windows2012R2为例   其他版本都大同小异   可以按照这个来 1) 点击Windows云服务器左下角[开始(Start)],选择[服务器管理器(Server Manager)],打 ...

  10. IIC挂死问题解决过程

    0.环境:arm CPU 带有IIC控制器作为slave端,带有调试串口. 1.bug表现:IIC slave 在系统启动后概率挂死,导致master无法detect到slave. 猜测1:认为IIC ...