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();
}
}
<?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();
}
}
相关文章推荐
- eclipse常用调试快捷键
- Java开发中的23种设计模式详解
- Java集合(5):HashSet
- Java中的集合框架
- JDBC数据类型与Java数据类型对应关系
- javaWeb后台版登陆注册
- SpringMVC简单配置
- 求素数算法-Java
- java中String byte HexString的转换
- spring security 与cas 结合
- 分享一下jdk重装后,javac命令可以执行,但java命令不能执行的解决方式
- java的static块执行时机
- Java动态代理详解(转载)
- java基础总结_04
- java.lang.ClassNotFoundException: Didn't find class "*****Activity" on path: /data/ap
- 【Heritrix 04】heritrix.properties+java.util.logging.Logger
- Java集合类
- 源码分析-java-AbstractList-subList、RandomAccess、equals和hashCode
- 使用zkClient连接zookeeper服务
- 第4条:消除过期的对象