Spring面向切面编程
一、在Spring容器中详细配置(增强)
首先导入以下jar包
接着写好Dao层和Service层,最后写Aop实体类以及在Spring容器中的配置(以下详细描述四种增强)
第一种:Throws异常增强(当目标方法抛出异常时调用)
Aop实体类:
/**
* @param joinPoint 所有动态代理的类的信息
*/
public void afterError(JoinPoint joinPoint,RuntimeException e){
System.out.println(joinPoint.getSignature().getName()+"这个方法的异常信息"+e.getMessage());
}
Spring容器中配置
<?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-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"<