项目中WebService使用Spring容器的配置

    <context:component-scan base-package="com.huawei.support">
        <context:include-filter type="annotation"
            expression="org.aspectj.lang.annotation.Aspect" />
    </context:component-scan>

扫描采用注解元数据的包是com.huawei.support包,并采用过滤器,类型是注解,就是说如果这个类采用了org.aspectj.lang.annotation.Aspect注解,就排除在扫描外。

--------------------------------------------------------------------------------------

<aop:aspectj-autoproxy proxy-target-class="true" />  动态实现代理,就是可以用类里的注解实现AOP代理,并用强制使用CGlib

spring对AOP的支持:

a、若目标对象实现了接口,默认情况下会采用JDK的动态代理实现AOP;

b、若目标对象实现了接口,可以强制使用CGLIB实现AOP;

c、若目标对象没有实现接口,必须采用CGLIB库。spring会自动在JDK动态代理和CGLIB之间转换;

强制使用CGLIB实现AOP:

a、添加CGLIB库

b、在spirng配置文件中加:<aop:aspectj-autoproxy proxy-target-class="true"/>

JDK动态代理只能对实现了接口的类生成代理,而不能针对类;

CGLIB是针对类实现代理,主要是对指定的类生成一个子类,覆盖其中的方法。因为是继承,所以类或方法最好不要声明为final。

---------------------------------------------------------------------------------

 <jaxws:endpoint id="certificateWS" implementor="#certificateWsImpl"
        address="/certificateWs">
        <jaxws:inInterceptors>
            <ref bean="authInterceptor" />
        </jaxws:inInterceptors>
    </jaxws:endpoint>

CXF客户端访问服务端四种方式

<?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">
    <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" />
    <!-- 第一种方式 -->
    <jaxws:endpoint id="helloWorld" implementor="cxf.server.HelloWorldImpl" address="/HelloWorld" />
    
    <!-- 第二种方式 -->
    <bean id="helloWorldImpl" class="cxf.server.HelloWorldImpl"/>
    <jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl" address="/HelloWorld"/>
    <!-- 这种方式,在老版本中这个是不能引用Ioc容器中的对象,但在2.x中可以直接用#id或#name的方式发布服务 -->   

<!-- 第三种方式 --> <jaxws:server id="helloWorld" serviceClass="cxf.server.HelloWorld" address="/HelloWorld"> <jaxws:serviceBean> <bean class="cxf.server.HelloWorldImpl"/> </jaxws:serviceBean> </jaxws:server> </beans>

第四种方式程序调用:

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.setServiceClass(PODownstreamWebService.class);
        factory.setAddress("http://localhost/service/soap/xml/poDownstream");
        PODownstreamWebService service = (PODownstreamWebService) factory.create();
        PurchaseOrder purchaseOrder = new PurchaseOrder();
        service.downPOToPAQ(purchaseOrder);

jaxws:inInterceptors 是装配输入拦截器,进行一些预处理,还有输出拦截器outInterceptors

 这里使用了一个判断用户名和密码的拦截器authInterceptor,代码参见http://www.cnblogs.com/onlywujun/archive/2013/01/06/2847800.html
原文地址:https://www.cnblogs.com/onlywujun/p/2846386.html