Spring Study[9]

來源:互聯網
上載者:User

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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.