The difference between Struts2 interceptor and spring AOP

Source: Internet
Author: User

While learning about the spring AOP technology, we found that it was very similar to the function of the interceptor that had been done before, and began to carry out a thorough study of what was the relationship between the two.

We know that Struts2 uses interceptors primarily to handle user requests, OGNL usage, form validation, and so on.

The spring interceptor is mainly manifested in the aspect of AOP transaction management, as well as the display of some errors or unusual logs by configuring spring's log Interceptor. The struts interceptor is for struts, such as the SSH project will use AOP, if the simple struts project naturally use struts itself interceptor, the final effect is the same, for the application is not different, but for the bottom-up implementation of the way there is a subtle difference! Interceptors are an implementation of AOP, and the Struts2 interceptor uses XWORK2 interceptor! Spring's AOP is based on the IOC, and its bottom layer is implemented by the combination of dynamic agent and Cglib agent.
1  Public classIntercept {2  PrivateLogger log = Loggerfactory.getlogger (cacheintercept.class);3  4  /**5 * Block the action method under the package6   * 7   * @paramexamples of PJP real methods8   * @returnThe return value of a real method or procedure9   */Ten@Around ("Execution (* package name. Action (..))") One   PublicObject Doaround (Proceedingjoinpoint PJP)throwsThrowable { A    //the real way to get intercepted -Object target =pjp.gettarget (); -    //Get class name theString ClassName =Target.getclass (). GetName (); -Log.debug ("Run Doaround with Class" +className); -     returnpjp.proceed (); -    +  } -   + in the configuration file, add: A<context:annotation-config/> at<context:component-scan base- Package= "Package name"/> -<aop:aspectj-autoproxy/>

The difference between Struts2 interceptor and spring AOP

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.