zoukankan      html  css  js  c++  java
  • (八)CXF之用spring添加拦截器

    一、案例

    <?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或者其他服务器即可生效。
  • 相关阅读:
    Android ListView常用用法
    android ListView详解
    /使用匿名内部类来复写Handler当中的handlerMessage()方法
    android Handler的使用(一)
    Android之Handler用法总结
    动态设置android:drawableLeft|Right|Top|Bottom
    Android Drawable Resource学习(十)、ScaleDrawable
    Android开发——关于onCreate的解读
    onCreate()方法中的参数Bundle savedInstanceState 的意义用法
    Android之drawable state各个属性详解
  • 原文地址:https://www.cnblogs.com/shyroke/p/7978744.html
Copyright © 2011-2022 走看看