Spring Learning (schema-based)---AOP (configuration-based AOP implementation)--Configuring Pointcuts Pointcut

Source: Internet
Author: User

Execution connection points for matching method execution

    • Execution (Public * * (..))
    • Execution (* set* (..))
    • Execution (* com.xyz.service.accountservice.* (..))
    • Execution (* com.xyz.service). (..))
    • Execution (* Com.xyz.service ... (..))
    • Within (com.xyz.service.*) (only in Spring AOP)
    • Within (Com.xyz.service. *) (only in Spring AOP)
    • This (Com.xyz.service.AccountService) (only in Spring AOP)
    • ....

For a few examples:

    • Execution (Public * * (..)) When a pointcut is executed for all public methods
    • Execution (* set* (..)) The Pointcut is the method at which all set start is executed
    • Execution (* com.xyz.service.accountservice.* (..)) When a pointcut is executed for all methods in the Accountservice class
    • Execution (* com.xyz.service).            (..)) When a pointcut is executed for all methods under the Com.xyz.service package
    • Execution (* Com.xyz.service ...            (..)) When a pointcut is executed for all methods under the Com.xyz.service package and its child packages
    • Within (com.xyz.service.*) (only in Spring AOP)
    • Within (Com.xyz.service. *) (only in Spring AOP) within used to match execution methods within the development type
    • This (Com.xyz.service.AccountService) (only in Spring AOP) This is used to match the execution method of the current AOP proxy object type

Other

    • Target (Com.xyz.service.AccountService) (only in Spring AOP) target is used to match the execution method of the current target object type
    • Args (java.io.Serializable) (only in Spring AOP) args is used to match the currently executing method of the passed parameter to the specified type of execution method

annotation-based matching

    • @target (Org.springframework.transaction.annotation.Transactional) (only in Spring AOP)
    • @within (Org.springframework.transaction.annotation.Transactional) (only in Spring AOP)
    • @annotation (Org.springframework.transaction.annotation.Transactional) (only in Spring AOP)
    • @args (com.xyz.security.Classified) (only in Spring AOP)

Realize:

<aop:config>          <aop:pointcut id= "businessservice" expression= "Execution (* com.aop.schema). (..))" >                    </aop:pointcut></aop:config>

Example:

Create a new two class

Package com.aop.schema;/** *  * Slice class * */public class Myaspect {}

Package com.aop.schema;/** *  * Business class * */public class Apsectbiz {}

XML configuration:

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" Xmlns:co ntext= "Http://www.springframework.org/schema/context" xsi:schemalocation= "Http://www.springframework.org/schema /beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd HTTP://WWW.SPRINGFRAMEWORK.O Rg/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd "> <bea n id= "Myaspect" class= "Com.aop.schema.MyAspect" ></bean> <bean id= "apsectbiz" class= "com.aop.schema.Ap            Sectbiz "></bean> <aop:config> <aop:aspect id=" MYASPECTAOP "ref=" Myaspect "> <aop:pointcut id= "mypointcut" expression= "Execution (* com.aop.schema.apsectbiz.* (..))"/> </aop:aspec T> </aop:config></beans> 

Spring Learning (schema-based)---AOP (configuration-based AOP implementation)--Configuring Pointcuts Pointcut

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.