Spring AOP Design

Spring IOC design to the design pattern: the factory mode, Template Method, singleton

Spring AOP related to the design pattern: the factory model, proxy mode

 

1, Spring AOP target

The crosscutting concerns dispersed throughout the program spun off, and in a centralized manner expression

Allows developers to concentrate on business logic, rather than the non complex function code, simplifies the programming unit tests

Scenario:

  Journal

  Safety

  Affairs

 

2, AOP core concepts

Advice (notification)

  Defined behavior at the point of connection, carried out around the method call injection

Pointcut (the cut point)

  Determine which application notice at the point of connection

Advisor (notifier)

  Advice combination and Pointcut

 

3, Spirng AOP achieve

ProxyFactoryBean

  --FactoryBean implementation that builds an  AOP proxy based on beans in Spring BeanFactory.

  - the underlying source of Spring AOP implementation and

 

4, ProxyFactoryBean typical configuration

 

 5, ProxyFactoryBean configuration

target

  Target audience, you need to be reinforced section

proxyInterfaces

  The proxy object interfaces implemented

interceptorNames

  Notifier (Advisor) list, notifier includes notification (the Advice) and pointcuts (Pointcut)

 

6, ProxyFactoryBean role 

  In general, the role of the following sentence available ProxyFactoryBean outlined

  To create a proxy object for the target object, the target object will call the method to call to the appropriate agent object methods, and can perform a defined method for each notifier matching before and after the proxy object method call.

 

7, create the target proxy object

Spring to create the target object in two ways

  JDK dynamic proxies

  CGLIB

 

8, JDK dynamic proxies

If the target object to generate a proxy object implements the interface, then Spring will pass JDK dynamic proxy as the target object

 

 

9、DefaultAopProxyFactory

	public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
		if (config.isOptimize() || config.isProxyTargetClass() || hasNoUserSuppliedProxyInterfaces(config)) {
			Class targetClass = config.getTargetClass();
			if (targetClass == null) {
				throw new AopConfigException("TargetSource cannot determine target class: " +
						"Either an interface or a target is required for proxy creation.");
			}
			if (targetClass.isInterface()) {
				return new JdkDynamicAopProxy(config);
			}
			if (!cglibAvailable) {
				throw new AopConfigException(
						"Cannot proxy target class because CGLIB2 is not available. " +
						"Add CGLIB to the class path or specify proxy interfaces.");
			}
			return CglibProxyFactory.createCglibProxy(config);
		}
		else {
			return new JdkDynamicAopProxy(config);
		}
	}

  

 

Guess you like

Origin www.cnblogs.com/linlf03/p/11184428.html