项目结构
![](https://images2015.cnblogs.com/blog/731047/201609/731047-20160906143917113-1307743275.png)
程序代码
HelloImpl.java
![](https://images2015.cnblogs.com/blog/731047/201609/731047-20160906143917582-254900244.png)
WorldImpl.java
![](https://images2015.cnblogs.com/blog/731047/201609/731047-20160906143917832-469087439.png)
定义切面类
![](https://images2015.cnblogs.com/blog/731047/201609/731047-20160906143918223-173492969.png)
package org.crazyit.app.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
// 定义一个切面
@Aspect
public class AuthAspect
{
// 匹配org.crazyit.app.service.impl包下所有类的、
// 所有方法的执行作为切入点
@Before("execution(* org.crazyit.app.service.impl.*.*(..))")
public void authority()
{
System.out.println("模拟执行权限检查");
}
}
配置
![](https://images2015.cnblogs.com/blog/731047/201609/731047-20160906143919113-913093362.png)
<?xml version="1.0" encoding="GBK"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="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/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<!-- 指定自动搜索Bean组件、自动搜索切面类 -->
<context:component-scan base-package="org.crazyit.app.service
,org.crazyit.app.aspect">
<context:include-filter type="annotation"
expression="org.aspectj.lang.annotation.Aspect"/>
</context:component-scan>
<!-- 启动@AspectJ支持 -->
<aop:aspectj-autoproxy/>
</beans>
测试
![](https://images2015.cnblogs.com/blog/731047/201609/731047-20160906143920082-1523467665.png)
![](https://images2015.cnblogs.com/blog/731047/201609/731047-20160906143920332-1544098949.png)
链接:
《@AfterReturning增强处理简单示例》http://www.cnblogs.com/ssslinppp/p/4633496.html
《@After后向增强处理简单示例》http://www.cnblogs.com/ssslinppp/p/4633427.html
《@Before前向增强处理简单示例》 http://www.cnblogs.com/ssslinppp/default.html?page=7
附件列表
转载请标明出处:http://www.cnblogs.com/ssslinppp/