Spring+structs2 related to spring AOP in projects implemented by

Source: Internet
Author: User



Spring+structs2 related to spring AOP in projects implemented by

1. The action in a project that is generally designed to facilitate the development of STRUCTS2 will establish a baseaction if you inherit the subclasses of Baseaction for AOP, you can only specify Pointcut in AOP as Baseaction
If the corresponding Baseaction is inherited from Actionsupport, it is only possible to define pointcut in AOP as Actionsupport.
Because the spring-generated proxy class, there is only one method for the same name, that is, the subclass overrides the parent class's method, only one, so if cannot find the proxy class directly implements the interface, will look for its top class superclass to look for.

2. If it is annotated, the principle is the same, because it is not good to change the corresponding class in the Actionsupport to add the corresponding annotations, so you can not inherit actionsupport.

3. For classes that are not singleton mode (none singleton), you need to turn on proxy-target-class= "true", use Cglib for AOP proxy processing,
If it is a business class, it is generally an interface, and you can For the action class, add
as shown below
  <aop:aspectj-autoproxy  proxy-target-class= "true"/> for annotations:
  The
  <aop:config proxy-target-class= "true" for the way XML is configured is shown below
  for an additional element with an AOP interceptor
 <bean name= "Xxaspet"   class= "Com.xx.aop.LogAspect"/>
 <bean name= "Loggingautoproxy"
 class= "Org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" >      
 <property name= "Proxytargetclass" value= "true"/>
 <property name= "BeanNames" > <value>.*</value></property>
 <property name= "Interceptornames" >
   <list>
   <value>xxaspet</value>
  </list>
 </property>
 </bean>

4. For structs, it is generally necessary to increase the <constant name= "Struts.objectFactory.spring.autoWire.alwaysRespect" value= "true"/>
In order to use spring's assembly class first in Structs2, Spring is responsible for loading and initializing the class.


5. Related pointcut Description: Execution used to match the execution of the method of the connection point;
Within is used to match method execution within a specified type;
This is used to match the execution method of the current AOP proxy object type, and note that it is the type matching of the AOP proxy object, which may include the introduction of the interface and type matching;
Target is used to match the execution method of the current target object type, and note that the target object type matches, which does not include the introduction interface and the type matching;
Args is used to match the execution method of the currently executing method passed in with the specified type of parameter;
@within used to match so hold the method within the specified annotation type;
@target the execution method used to match the current target object type, where the target object holds the specified annotation;
@args used to match the current execution of the method passed in the parameter holding the specified annotation for execution;
@annotation the method used to match the current execution method holding the specified annotation;
bean:spring an AOP extension, ASPECTJ does not have a method for executing a bean object that matches a particular name for an indicator;
Reference Pointcut: Indicates references to other named Pointcuts, only @apectj style support, schema style is not supported.

Generally, pointcut can use within to specify all public methods in the class of the corresponding package and the child package.
You can use execution to specify the corresponding public method in the class of the corresponding package and the child package
You can use @annotation to specify corresponding annotations in the corresponding packet and sub-package class

Where there may be a misunderstanding, a friend who wants to see

Spring+structs2 related to spring AOP in projects implemented by

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.