Spring Study[9]

Using dynamic pointcuts:

Spring provides one built-in dynamic pointcut: ControlFlowPointcut.
<beans>
 <bean id="myServiceTarget" class="MyServiceImpl"/>
 <bean id="servletInterceptor" class="MyServletInterceptor"/>
 <bean id="servletPointcut" class="org.springframework.aop.support.ControlFlowPointcut">
 <constructor-arg>
  <value>javax.servlet.http.HttpServlet</value>
 </constructor-arg>
 </bean>
 <bean id="servletAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
  <property name="advice">
   <ref bean="servletInterceptor"/>
  </property>
  <property name="pointcut">
   <ref bean="servletPointcut"/>
  </property>
 </bean>
 <bean id="service" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="proxyInterfaces">
   <value>MyService</value></property>
  <property name="interceptorNames">
   <list>
    <value>servletAdvisor</value>
   </list>
  </property>
  <property name="target">
   <value ref="myServiceTarget">
  </property>
 </bean>
</beans>

the ControlFlowPointcut is the only dynamic pointcut implementation provided by Spring. But remember, you can create your own dynamic
pointcut by implementing MethodMatcher and have the isRuntime() method return true.

Creating introductions:
Introductions affect an entire class.

Spring implements introductions through a special subinterface of MethodInterceptor: IntroductionMethodInterceptor. This interface adds one additional
method:
boolean implementsInterface (Class intf);


Using ProxyFactoryBean:
In most ProxyFactoryBean configurations, you will need to be concerned with only a few of these properties. The three properties you will probably use most
often are target, proxyInterfaces, and interceptorNames.

The target property defines what bean should be the target object of the generated proxy object.

The proxyInterfaces property is a list of interfaces that should be implemented by the beans created by the factory.
The interceptorNames property is a list of advisor or advice bean names that should be applied to the target bean.

Autoproxying:
Spring comes with two classes that provide this support: BeanNameAutoProxyCreator and DefaultAdvisorAutoProxyCreator.
BeanNameAutoProxyCreator generates proxies for beans that match a set of names.
The more powerful autoproxy creator is the DefaultAdvisorAutoProxyCreator.

你可能感兴趣的:(spring)