`
jun0112
  • 浏览: 21809 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
阅读更多

目录
教学目标
AOP介绍
代理模式
简单代理
需求
实现
动态代理
AOP概念
Spring的自定义AOP
准备工作
使用模式的AOP
使用注释的AOP
AOP声明风格的选择
Spring的事务管理
事务隔离级别
事务传播类型
事务管理的方式
Spring集成Hibernate
Spring的高级功能
多配置文件的import机制
使用properties文件
对测试代码的IOC
Spring集成Hibernate
基本的集成步骤
代码的处理
配置文件
事务的处理
Lob字段的处理
通用DAO增强的分页查询功能
练习和作业

Spring与AOP

1. 教学目标
理解AOP的基本原理 
掌握自定义Spring AOP的方法 
熟练掌握Spring有关事务等AOP的配置和使用 
掌握自定义Spring AOP的方法 
掌握Spring与Hibernate集成和使用方法 

2. AOP介绍

AOP,Aspect Oriented Programming,面向方面编程。 

AOP原理下面介绍。 

AOP的作用:对程序解藕和关注分离。 

应用场合: 
事务处理 
权限控制 
审计日志 
其他 

3. 代理模式

Proxy模式,代理模式,是AOP的前身。 

3.1. 简单代理

示例见:http://spring2demo.googlecode.com/svn/branches/aop_proxy 

3.1.1. 需求

功能需求: 

为ProductDaoImpl的save方法增加授权检查功能 

为ProductDaoImpl的save方法增加事务的处理功能 

为ProductDaoImpl的save方法增加打开关闭连接的功能 

系统需求: 

Dao实现应该不管怎么获得Connection, 因为Connection有可能通过数据库驱动, 也可能通过jndi等获得; 

Dao实现应该不管事务的处理, 因为多个Dao方法可能组成一个原子事务; 

Dao实现应该不管谁有权限访问. 

Dao实现应该专注于有关sql的查询和操作等. 

这种思路就是关注分离 

3.1.2. 实现

实现代理模式的一般形式: 

 

使用工厂模式和单例模式集成,见ProductDaoFactory 

切换行号显示切换行号显示 
  1 public abstract class ProductDaoFactory {
  2 
  3 private static ProductDao productDao;
  4 
  5 public static ProductDao getProductDao() {
  6 if (productDao == null) {
  7 productDao = new ProductDaoTransactionProxy(new ProductDaoImpl());
  8 productDao = new ProductDaoConnectionProxy(productDao);
  9 productDao = new ProductDaoAuthorizationProxy(productDao);
  10 }
  11 
  12 return productDao;
  13 }

调用顺序: 

 

代理对调用者是透明的: 

 

代理是可以级联的 

3.2. 动态代理

见示例:https://spring2demo.googlecode.com/svn/branches/aop_dynaproxy 

简单代理模式实现的缺点: 
产生大量的代理类 
产生的代理类较难复用给其他类复用 

动态代理解决了简单代理的问题。 

动态代理实现的方式: 
通过java.lang.reflect包中的动态代理支持 
通过类的继承(使用类的继承和cglib库) 

4. AOP概念

是对代理模式运用的理论化和实现机制的完善. 

见下面的图: 

 
target object: 目标对象 
aspect: 切面 
joinpoint: 连接点, 切面切入的点 
pointcut: 配合连接点, 说明连接点的断言和表达式 
advice: 通知, 在连接点要执行的代码 

通知的种类: 
前置通知 
返回后通知 
抛出异常后通知 
后通知 
环绕通知 

5. Spring的自定义AOP

5.1. 准备工作

类库: 
lib\asm\*.jar 
lib\aspectj\*.jar 

修改配置文件的schema部分 

<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.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

5.2. 使用模式的AOP

见示例:http://spring2demo.googlecode.com/svn/branches/aop_schema 

修改配置文件的schema部分: 

<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.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

将目标对象和切面对象配置为bean: 

  <bean id="productDaoTarget"
  class="com.googlecode.spring2demo.aop.spring.schema.ProductDaoImpl" />
  <bean id="authorizationAspect"
  class="com.googlecode.spring2demo.aop.spring.schema.AuthorizationAspect" />
  <bean id="jdbcConnectionAspect"
  class="com.googlecode.spring2demo.aop.spring.schema.JdbcConnectionAspect" />
  <bean id="transactionAspect"
  class="com.googlecode.spring2demo.aop.spring.schema.TransactionAspect" />

配置AOP: 

  <aop:config>
  <aop:pointcut id="productDaoPointcut"
  expression="execution(* com.googlecode.spring2demo.aop.spring.schema.ProductDao.save(..))" />
  <aop:aspect id="authorization" ref="authorizationAspect">
  <aop:before pointcut-ref="productDaoPointcut"
  method="checkAuthorization" />
  </aop:aspect>
  <aop:aspect id="jdbcConnection" ref="jdbcConnectionAspect">
  <aop:before pointcut-ref="productDaoPointcut"
  method="doConnection" />
  <aop:after pointcut-ref="productDaoPointcut"
  method="closeConnection" />
  </aop:aspect>
  <aop:aspect id="transaction" ref="transactionAspect">
  <aop:around pointcut-ref="productDaoPointcut"
  method="doTransaction" />
  <aop:after-throwing pointcut-ref="productDaoPointcut"
  method="doRollback" />
  </aop:aspect>
  </aop:config>

<aop:config>标签: AOP配置标签 

<aop:pointcut>标签: 设置切入点, expression表达式, execution(* spring.aop.schema.ProductDao.save(..)) 

<aop:aspect>标签: 设置切面 

<aop:aroud>/<aop:after-throwing>/<aop:before >/<aop:after>: 通知 

5.3. 使用注释的AOP

见示例:http://spring2demo.googlecode.com/svn/branches/aop_annotation 

配置启用@Aspectj支持 

<aop:aspectj-autoproxy />

配置bean 

  <bean id="productDaoTarget"
  class="com.googlecode.spring2demo.aop.spring.annotation.ProductDaoImpl" />
  <bean id="authorizationAspect"
  class="com.googlecode.spring2demo.aop.spring.annotation.AuthorizationAspect" />
  <bean id="jdbcConnectionAspect"
  class="com.googlecode.spring2demo.aop.spring.annotation.JdbcConnectionAspect" />
  <bean id="transactionAspect"
  class="com.googlecode.spring2demo.aop.spring.annotation.TransactionAspect" />

配置切面和切入点: 

切换行号显示切换行号显示 
  1 @Aspect
  2 public class AuthorizationAspect {
  3 
  4 @Before("execution(* com.googlecode.spring2demo.aop.spring.annotation.ProductDao.save(..))")
  5 public void checkAuthorization() {
  6 System.out.println("检查是否有权限");
  7 }
@Aspect: 切面 

@Before/@After/@Around/@AfterThrowing: 通知 

5.4. AOP声明风格的选择

一般尽量选择注释风格. 

除非: 运行在java 5之前的jdb版本. 

注释风格的优点: 
DRY原则: Don't Repeat Yourself, 不要重复自己. 模式风格, 需求的实现分割为类的声明和xml配置文件. 
注释风格可以表示模式风格不能表达的复杂限制 
可以兼容Spring AOP和AspectJ 

6. Spring的事务管理

6.1. 事务隔离级别

预备知识: 
脏读(dirty reads)一个事务读取了另一个未提交的并行事务写的数据。 
不可重复读(non-repeatable reads) 一个事务重新读取前面读取过的数据, 发现该数据已经被另一个已提交的事务修改过。 
幻读(phantom read) 一个事务重新执行一个查询,返回一套符合查询条件的行, 发现这些行因为其他最近提交的事务而发生了改变. 当一个事务在某一表中进行数据查询时,另一事务恰好插入了满足了查询条件的数据行。则前一事务在重复读取满足条件的值时,将得到一个额外的“影象“值。 

事务隔离级别: 
ISOLATION_DEFAULT: 使用数据库默认的事务隔离级别; 
ISOLATION_READ_UNCOMMITTED: 最低的隔离级别, 允许别外一个事务可以看到这个事务未提交的数据. 可能产生脏读, 不可重复读和幻像读. 
ISOLATION_READ_COMMITTED: 保证一个事务修改的数据提交后才能被另外一个事务读取. 避免脏读出现, 但是可能会出现不可重复读和幻像读. 
ISOLATION_REPEATABLE_READ: 防止脏读, 不可重复读. 
ISOLATION_SERIALIZABLE: 事务被处理为顺序执行.除了防止脏读, 不可重复读外, 还避免了幻像读. 

6.2. 事务传播类型

PROPAGATION_REQUIRED: 如果存在一个事务, 则支持当前事务. 如果没有事务则开启一个新的事务.<--常用 

PROPAGATION_SUPPORTS: 如果存在一个事务, 支持当前事务. 如果没有事务, 则非事务的执行.<--常用 
PROPAGATION_MANDATORY: 如果已经存在一个事务, 支持当前事务. 如果没有一个活动的事务, 则抛出异常. 

PROPAGATION_REQUIRES_NEW: 总是开启一个新的事务. 如果一个事务已经存在, 则将这个存在的事务挂起.<--嵌套事务 
PROPAGATION_NOT_SUPPORTED: 总是非事务地执行, 并挂起任何存在的事务 
PROPAGATION_NEVER: 总是非事务地执行, 如果存在一个活动事务, 则抛出异常 

PROPAGATION_NESTED: 如果一个活动的事务存在, 则运行在一个嵌套的事务中. 如果没有活动事务, 则按TransactionDefinition.PROPAGATION_REQUIRED 属性执行. 

6.3. 事务管理的方式

声明式事务管理: 推荐使用 
<tx:advice id="transactionAdvice"
  transaction-manager="transactionManager">
  <tx:attributes>
  <tx:method name="save*" propagation="REQUIRED" />
  <tx:method name="create*" propagation="REQUIRED" />
  <tx:method name="update*" propagation="REQUIRED" />
  <tx:method name="delete*" propagation="REQUIRED" />
  <tx:method name="*" propagation="SUPPORTS" read-only="true" />
  </tx:attributes>
</tx:advice>
 
编程式事务管理: 
切换行号显示切换行号显示 
  1 DefaultTransactionDefinition def = new DefaultTransactionDefinition();
  2 def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
  3 
  4 TransactionStatus status = txManager.getTransaction(def);
  5 try {
  6 // execute your business logic here
  7 }
  8 catch (MyException ex) {
  9 txManager.rollback(status);
  10 throw ex;
  11 }
  12 txManager.commit(status);
  13 
  14  

7. Spring集成Hibernate

见示例:http://spring2demo.googlecode.com/svn/tags/sh_r1_2 

7.1. Spring的高级功能

7.1.1. 多配置文件的import机制

见:test.config.xml 

  <!-- 导入其他组件的配置 -->
  <import
  resource="classpath:com/googlecode/spring2demo/dao/config.xml" />
  <import
  resource="classpath:com/googlecode/spring2demo/product/config.xml" />

7.1.2. 使用properties文件

见:test.config.xml 

  <!-- 属性文件 -->
  <bean id="propertyConfigurer"
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
  <value>
  classpath:com/googlecode/spring2demo/product/config.properties
  </value>
  </property>
  </bean>
这里是测试使用,一般properties放在classpath根下。 

7.1.3. 对测试代码的IOC

见代码:ProductActionTest 

切换行号显示切换行号显示 
public class ProductActionTest extends
  AbstractDependencyInjectionSpringContextTests {

  private ProductAction productAction;

  public void setProductAction(ProductAction productAction) {
  this.productAction = productAction;
  }

  @Override
  protected String[] getConfigLocations() {
  return new String[] { "classpath:com/googlecode/spring2demo/product/test.config.xml" };
  }

  @Test
  public void test() throws IOException {
  this.productAction.saveAll();
  }

继承AbstractDependencyInjectionSpringContextTests 
覆盖protected String[] getConfigLocations()方法 

7.2. Spring集成Hibernate

7.2.1. 基本的集成步骤

7.2.1.1. 代码的处理

编写HibernateDao类,继承org.springframework.orm.hibernate3.support.HibernateDaoSupport 

编写有关增删改查方法,使用超类的HibernateTemplate: 

切换行号显示切换行号显示 
  1 public void saveOrUpdate(T entity) {
  2 this.getHibernateTemplate().saveOrUpdate(entity);
  3 }

复杂处理,需要HibernateTemplate.execute()方法,方法参数是HibernateCallback接口。 

HibernateCallback是回调接口,需要实现:public Object doInHibernate(Session session)方法。 

比如: 

切换行号显示切换行号显示 
  1 pagination.setRecordSum((Integer) this.getHibernateTemplate().execute(
  2 new HibernateCallback() {
  3 
  4 public Object doInHibernate(Session session)
  5 throws HibernateException, SQLException {
  6 Criteria criteria = session.createCriteria(type);
  7 criteriaCallBack.setCriteria(criteria);
  8 Integer count = (Integer) criteria.setProjection(
  9 Projections.count(Projections.id().toString()))
  10 .uniqueResult();
  11 return count;
  12 }
  13 }));

HibernateTemplate封装Hibernate Session对象,并做了增强和简化。 

7.2.1.2. 配置文件

配置datasource: 

  <!-- 有关datasource的配置 -->
  <bean id="dataSource"
  class="com.mchange.v2.c3p0.ComboPooledDataSource"
  destroy-method="close">
  <property name="driverClass" value="${driverClass}" />
  <property name="jdbcUrl" value="${jdbcUrl}" />
  <property name="user" value="${user}" />
  <property name="password" value="${password}" />

  <property name="initialPoolSize" value="1" />
  </bean>

配置hibernate映射文件的列表: 

  <!-- 有关hibernate映射文件的配置 -->
  <bean id="mappingResources" class="java.util.ArrayList">
  <constructor-arg>
  <list>
  <value>
  com/googlecode/spring2demo/product/entity.hbm.xml
  </value>
  </list>
  </constructor-arg>
  </bean>

配置sessionFactory: 

  <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="mappingResources" ref="mappingResources" />
  <property name="lobHandler">
  <bean class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
  </property>
  <property name="hibernateProperties">
  <props>
  <prop key="hibernate.dialect">
  ${hibernate.dialect}
  </prop>
  <prop key="hibernate.cache.use_query_cache">false</prop>
  <prop key="hibernate.show_sql">
  ${hibernate.show_sql}
  </prop>
  <prop key="hibernate.cache.provider_class">
  org.hibernate.cache.NoCacheProvider
  </prop>
  <prop key="hibernate.hbm2ddl.auto">
  ${hibernate.auto}
  </prop>
  </props>
  </property>
  <property name="schemaUpdate">
  <value>${hibernate.schemaUpdate}</value>
  </property>
  </bean>

配置事务管理器: 

  <!-- 事务管理配置 -->
  <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
  </bean>

配置抽象的dao Bean: 

  <!-- Dao实现 -->
  <bean id="dao" class="com.googlecode.spring2demo.dao.HibernateDao" abstract="true">
  <property name="sessionFactory" ref="sessionFactory" />
  </bean>

配置具体的dao Bean: 

  <bean name="productDao"
  class="com.googlecode.spring2demo.product.ProductDaoImpl" parent="dao">
  <property name="type"
  value="com.googlecode.spring2demo.product.Product" />
  </bean>

7.2.2. 事务的处理

使用基于annotation的事务处理方式。 

spring为事务处理定制了更为简洁的annotation。 

在配置文件中: 

<tx:annotation-driven />

在需要事务的接口或者实现类的方法加入annotation 

切换行号显示切换行号显示 
  1 /**
  2 * 更新对象
  3 * 
  4 * @param entity
  5 */
  6 @Transactional(propagation = Propagation.REQUIRED)
  7 public void update(T entity);
  8 
  9 /**
  10 * 通过id得到对象
  11 * 
  12 * @param id
  13 * @return
  14 */
  15 @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
  16 public T findById(PK id);

通过日志理解事务的创建和提交过程。 

7.2.3. Lob字段的处理

hibernate可以处理lob字段。 

使用Spring可以更加方便。 

实体类:Photo 

切换行号显示切换行号显示 
  1 public class Photo {
  2 private String id;
  3 
  4 private String fileName;
  5 
  6 private String contentType;
  7 
  8 private byte[] data;

Hibernate映射文件: 

  <class name="Photo">
  <id name="id">
  <generator class="uuid" />
  </id>
  <property name="fileName" />
  <property name="contentType" />
  <property name="data"
  type="org.springframework.orm.hibernate3.support.BlobByteArrayType"
  length="1024000" />
  </class>

Spring配置文件: 

  <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="mappingResources" ref="mappingResources" />
  <property name="lobHandler">
  <bean class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
  </property>
如果是oracle 9i等,需要另外的lobHandler配置。 

7.2.4. 通用DAO增强的分页查询功能

通用DAO增强的分页查询功能:理论上,可以对复杂条件查询和分页,其中复杂条件由用户设置。 

自定义回调接口:CriteriaCallBack 

切换行号显示切换行号显示 
  1 public interface CriteriaCallBack {
  2 
  3 /**
  4 * Sets the criteria.
  5 * 
  6 * @param criteria
  7 * the criteria
  8 */
  9 public void setCriteria(Criteria criteria);

使用CriteriaCallBack接口的查询示例: 

切换行号显示切换行号显示 
  1 Pagination<Product>pagination=new Pagination<Product>();
  2 pagination.setNo(1);
  3 pagination.setSize(10);
  4 pagination.setConditon(new CriteriaCallBack(){
  5 @Override
  6 public void setCriteria(Criteria criteria) {
  7 Product product=new Product();
  8 product.setName("1");
  9 product.setIntroduction("1");
  10 criteria.add(Example.create(product).enableLike(MatchMode.ANYWHERE).excludeProperty("price"));
  11  
  12 }
  13 });
  14  
  15 this.productAction.browse(pagination);
  16  
  17 assert pagination.getResults().size()==1;

8. 练习和作业

独立完成课上的示例。 

work/training/java/jee/spring/aop (2008-04-08 08:27:19由marshal编辑)

分享到:
评论

相关推荐

    spring aop jar 包

    Spring AOP(Aspect Oriented Programming,面向切面编程)是Spring框架的重要组成部分,它提供了一种在不修改源代码的情况下,对程序进行功能增强的技术。这个"spring aop jar 包"包含了实现这一功能所需的类和接口,...

    Spring AOP 16道面试题及答案.docx

    Spring AOP,全称为Aspect Oriented Programming,是面向切面编程的一种编程范式,它是对传统的面向对象编程(OOP)的一种补充。在OOP中,核心是对象,而在AOP中,核心则是切面。切面是关注点的模块化,即程序中的...

    简单spring aop 例子

    Spring AOP(面向切面编程)是Spring框架的重要组成部分,它提供了一种模块化和声明式的方式来处理系统中的交叉关注点问题,如日志、事务管理、安全性等。本示例将简要介绍如何在Spring应用中实现AOP,通过实际的...

    spring aop 自定义注解保存操作日志到mysql数据库 源码

    3、对spring aop认识模糊的,不清楚如何实现Java 自定义注解的 4、想看spring aop 注解实现记录系统日志并入库等 二、能学到什么 1、收获可用源码 2、能够清楚的知道如何用spring aop实现自定义注解以及注解的逻辑...

    死磕Spring之AOP篇 - Spring AOP两种代理对象的拦截处理(csdn)————程序.pdf

    Spring AOP 是一种面向切面编程的技术,它允许我们在不修改源代码的情况下,对应用程序的特定部分(如方法调用)进行增强。在 Spring 中,AOP 的实现主要依赖于代理模式,有两种代理方式:JDK 动态代理和 CGLIB 动态...

    Spring AOP完整例子

    Spring AOP(面向切面编程)是Spring框架的核心特性之一,它允许开发者在不修改源代码的情况下,通过插入切面来增强或改变程序的行为。在本教程中,我们将深入探讨Spring AOP的不同使用方法,包括定义切点、通知类型...

    spring aop依赖jar包

    现在,我们回到主题——"springaop依赖的jar包"。在Spring 2.5.6版本中,使用Spring AOP通常需要以下核心jar包: - `spring-aop.jar`:这是Spring AOP的核心库,包含了AOP相关的类和接口。 - `spring-beans.jar`:...

    spring AOP 引入jar包,spring IOC 引入Jar包

    Spring AOP 和 Spring IOC 是 Spring 框架的两个核心组件,它们对于任何基于 Java 的企业级应用开发都至关重要。Spring AOP(面向切面编程)允许开发者在不修改源代码的情况下,通过“切面”来插入新的行为或增强已...

    反射实现 AOP 动态代理模式(Spring AOP 的实现原理)

    面向切面编程(AOP)是一种编程范式,旨在将横切关注点(如日志、安全等)与业务逻辑分离,从而提高模块化。...利用Java反射机制和Spring AOP框架,开发者可以方便地实现AOP,从而提升代码的模块化和可维护性。

    Spring AOP实现机制

    **Spring AOP 实现机制详解** Spring AOP(面向切面编程)是Spring框架的核心特性之一,它允许程序员在不修改源代码的情况下,通过“切面”来插入额外的业务逻辑,如日志、事务管理等。AOP的引入极大地提高了代码的...

    springAOP配置动态代理实现

    Spring AOP(面向切面编程)是Spring框架的重要组成部分,它允许程序员在不修改源代码的情况下,通过在运行时插入额外的行为(如日志记录、性能监控等)来增强对象的功能。动态代理则是Spring AOP实现的核心技术之一...

    Spring AOP面向方面编程原理:AOP概念

    ### Spring AOP面向方面编程原理:AOP概念详解 #### 一、引言 随着软件系统的日益复杂,传统的面向对象编程(OOP)逐渐暴露出难以应对某些横切关注点(cross-cutting concerns)的问题。为了解决这一挑战,面向方面编程...

    小马哥讲 Spring AOP 编程思想 - API 线索图.pdf

    在讨论Spring AOP(面向切面编程)时,首先需要理解几个核心概念。Spring AOP 是Spring框架提供的一个功能模块,它允许开发者将横切关注点(cross-cutting concerns)从业务逻辑中解耦出来,通过在方法调用前后进行...

    spring aop切面拦截指定类和方法实现流程日志跟踪

    ### Spring AOP 实现流程日志跟踪 #### 一、背景与目的 在现代软件开发过程中,为了确保系统的稳定性和可维护性,通常会引入非功能性的需求来增强应用程序的功能,比如日志记录、安全控制等。这些需求往往不是业务...

    spring aop 五个依赖jar

    Spring AOP(面向切面编程)是Spring框架的重要组成部分,它提供了一种模块化和声明式的方式来处理系统中的交叉关注点,如日志、事务管理等。在Java应用中,AOP通过代理模式实现了切面编程,使得我们可以将业务逻辑...

    Spring AOP 入门作者:廖雪峰

    ### Spring AOP 入门详解 #### 一、Spring AOP 概述 Spring AOP(Aspect Oriented Programming,面向切面编程)是Spring框架的一个关键特性,它为开发者提供了在运行时动态添加代码(即横切关注点或切面)到已有...

    Spring源码最难问题:当Spring AOP遇上循环依赖.docx

    Spring源码最难问题:当Spring AOP遇上循环依赖 Spring源码中最难的问题之一是循环依赖问题,当Spring AOP遇上循环依赖时,该如何解决? Spring通过三级缓存机制解决循环依赖的问题。 在Spring中,bean的实例化...

    spring AOP依赖三个jar包

    Spring AOP,即Spring的面向切面编程模块,是Spring框架的重要组成部分,它允许开发者在不修改源代码的情况下,对程序进行横切关注点的处理,如日志、事务管理等。实现这一功能,主要依赖于三个核心的jar包:aop...

    spring aop的demo

    在`springAop1`这个压缩包中,可能包含了一个简单的应用示例,展示了如何定义一个切面类,以及如何在该类中定义通知方法。例如,我们可能会看到一个名为`LoggingAspect`的类,其中包含了`@Before`注解的方法,用于在...

    基于注解实现SpringAop

    基于注解实现SpringAop基于注解实现SpringAop基于注解实现SpringAop

Global site tag (gtag.js) - Google Analytics