配置applicationContext.xml实现AOP
昨天是使用Annotation注解的方式实现的AOP,今天再将其改为使用配置文件来实现。使用这种方法的话,SecurityHandler类就又少了一大截的代码,只需要提供一个用于标识切点的方法即可。
package cn.ineeke.spring; public class SecurityHandler { private void printSomthing(){ System.out.println("--------Security----------"); } }
虽说类中是不需要使用注解了,但是这个东西肯定是得有的,只不过是将其转移到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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"> <bean id="securityHandler" class="cn.ineeke.spring.SecurityHandler"/> <bean id="userDAO" class="cn.ineeke.spring.UserDAOImpl"/> <aop:config> <aop:aspect id="securityAspect" ref="securityHandler"> <aop:pointcut id="addMethod" expression="execution(* *(..))"/> <aop:before method="printSomthing" pointcut-ref="addMethod"/> </aop:aspect> </aop:config> </beans>
调用方法同之前的一样,这样看起来应该比昨天那个清晰的多了,看标签也比较好容易理解。
除非另有声明,本站遵循【署名-非商业性使用-相同方式共享 3.0 共享协议】授权。
转载原创文章请注明,转载自:Neeke[http://www.ineeke.com]
本文链接: http://www.ineeke.com/archives/applicationcontext-aop/

谢谢楼主。新年快乐
够专业,这也难怪谷歌对你的博客评价这么高。