文件配置:
<!-- 前置通知 -->
<bean id="logBefore" class="org.wpc.aop.LogBefore"></bean>
<!-- 类与通知的关联 -->
<aop:config>
<aop:pointcut id="pointcut" expression="execution( public void org.wpc.iml.StudentServiceIml.addstudent())"/>
<aop:advisor advice-ref="logBefore" pointcut-ref="pointcut"></aop:advisor>
</aop:config>
前置通知类:
public class LogBefore implements MethodBeforeAdvice {
@Override
public void before(Method method, Object[] objects, Object o) throws Throwable {
System.out.println("前置通知...");
}
}
注意:在expression的表达中不用static,对于参数类和方法需要使用全名。
对于AOP通知类是在某一个方法前或后添加某一个补充,可以用来实现如登陆之前的验证,程序结束之后的清理数据等。类似于过滤器的效果。
本文详细介绍了如何在Spring框架中配置AOP前置通知,通过具体的代码示例,展示了如何创建前置通知类并将其应用于特定的方法调用之前,以实现如登录验证等功能。
4377

被折叠的 条评论
为什么被折叠?



