您的位置:首页 > 编程语言 > Java开发

Spring纯简单java对象切面

2016-07-19 15:54 716 查看
1:applicationcontext03.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"  

    xsi:schemaLocation="   

             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd   

             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd   

             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> 
             

<bean id="checkip" class="com.zn.service.impl.CheckipImpl"/>

<!-- 定义一个增强advice -->

<bean id ="checkHelper" class="com.zn.common.CheckHelperProxy"/>

<!-- 配置切点和通知--> 

<bean id ="checkHelperAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">     

 <property name="advice" ref="checkHelper"></property>     

 <property name="pattern" value=".*check"> </property>      

</bean> 

<!-- 自动代理配置 -->

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/> 

</beans>

2:测试类:MainTest03.java

package com.zn;

import org.springframework.context.ApplicationContext;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.zn.service.Checkipable;

public class MainTest03 {

public static void main(String args[]){
ApplicationContext ct = new ClassPathXmlApplicationContext("applicationcontext03.xml");
Checkipable ck = (Checkipable)ct.getBean("checkip");
ck.check();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: