码迷,mamicode.com
首页 > 编程语言 > 详细

Spring Aop 切点表达式

时间:2014-12-01 19:23:48      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:execution   target   within   表达式   连接点   

   在Spring AOP 中,通常需要借助AspectJ 的切点表达式语言来定义切点。重要的是Spring 中仅支持AspectJ切点指示器的一个子集。

Spring 支持的AspectJ的切点指示器

AspectJ 指示器 描述
args() 限制连接点匹配参数为执行类型的执行方法
@args() 限制连接点匹配参数由执行注解标注的执行方法
execution() 匹配连接点的执行方法
this() 限制连接点匹配AOP代理的Bean引用类型为指定类型的Bean
target() 限制连接点匹配目标对象为指定类型的类
@target() 限制连接点匹配目标对象被指定的注解标注的类
within() 限制连接点匹配匹配指定的类型
@within() 限制连接点匹配指定注解标注的类型
@annotation 限制匹配带有指定注解的连接点

 

Spring AOP 中常用的是:

Java代码 bubuko.com,布布扣bubuko.com,布布扣

  1. execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)  

  2.           throws-pattern?)  

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)
          throws-pattern?)

 匹配所有

       execution("* *.*(..)")

匹配所有以set开头的方法

        execution("* *.set*(..))

匹配指定包下所有的方法

        execution("* com.david.biz.service.impl.*(..))

匹配指定包以及其子包下的所有方法

        execution("* com.david..*(..)")

匹配指定包以及其子包下 参数类型为String 的方法

        execution("* com.david..*(java.lang.String))

 

 

Java代码 bubuko.com,布布扣bubuko.com,布布扣

  1. <?xml version="1.0" encoding="UTF-8"?>  

  2. <beans xmlns="http://www.springframework.org/schema/beans"  

  3.     xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  

  4.     xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"  

  5.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"  

  6.     xmlns:task="http://www.springframework.org/schema/task"  

  7.     xsi:schemaLocation="  

  8.         http://www.springframework.org/schema/beans  

  9.         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  

  10.         http://www.springframework.org/schema/context  

  11.         http://www.springframework.org/schema/context/spring-context-3.0.xsd  

  12.         http://www.springframework.org/schema/aop   

  13.         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  

  14.         http://www.springframework.org/schema/tx  

  15.         http://www.springframework.org/schema/tx/spring-tx-3.0.xsd  

  16.         http://www.springframework.org/schema/jee   

  17.         http://www.springframework.org/schema/jee/spring-jee-3.0.xsd  

  18.         http://www.springframework.org/schema/task    

  19.         http://www.springframework.org/schema/task/spring-task-3.1.xsd    

  20.         ">  

  21.     <context:component-scan base-package="com.david.*"/>  

  22.     <aop:aspectj-autoproxy />  

  23.     <context:property-placeholder location="classpath:META-INF/config.properties" />  

  24.     <!-- 定义数据源 -->  

  25.     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  

  26.         destroy-method="close">  

  27.         <property name="driverClass" value="${jdbc.ams.driver}" />  

  28.         <property name="jdbcUrl" value="${jdbc.ams.url}" />  

  29.         <property name="user" value="${jdbc.ams.username}" />  

  30.         <property name="password" value="${jdbc.ams.password}" />  

  31.         <property name="initialPoolSize" value="${initialSize}" />  

  32.         <property name="minPoolSize" value="${minPoolSize}" />  

  33.         <property name="maxPoolSize" value="${maxActive}" />  

  34.         <property name="acquireIncrement" value="${acquireIncrement}" />  

  35.         <property name="maxIdleTime" value="${maxIdleTime}" />  

  36.     </bean>  

  37.   

  38.     <!-- 定义jdbc模板类 -->  

  39.     <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">  

  40.         <property name="dataSource" ref="dataSource" />  

  41.     </bean>  

  42.   

  43.     <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">  

  44.         <property name="dataSource" ref="dataSource" />  

  45.         <property name="configLocation" value="classpath:META-INF/sqlmap/sqlmap.xml" />  

  46.     </bean>  

  47.   

  48.     <tx:advice id="txAdvice" transaction-manager="transactionManager">  

  49.         <tx:attributes>  

  50.             <tx:method name="addBook" propagation="REQUIRED" />  

  51.             <tx:method name="addUserBook" propagation="MANDATORY" />  

  52.             <tx:method name="deleteBook" propagation="REQUIRES_NEW" />  

  53.             <tx:method name="addNewBook" propagation="NEVER" />  

  54.             <tx:method name="addUser" propagation="NESTED" />  

  55.         </tx:attributes>  

  56.     </tx:advice>  

  57.     <bean id="transactionManager"  

  58.         class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  

  59.         <property name="dataSource" ref="dataSource" />  

  60.     </bean>  

  61.       

  62. </beans>  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans
		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
		http://www.springframework.org/schema/context
		http://www.springframework.org/schema/context/spring-context-3.0.xsd
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
		http://www.springframework.org/schema/tx
		http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
		http://www.springframework.org/schema/jee 
		http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
		http://www.springframework.org/schema/task  
        http://www.springframework.org/schema/task/spring-task-3.1.xsd  
		">
	<context:component-scan base-package="com.david.*"/>
	<aop:aspectj-autoproxy />
	<context:property-placeholder location="classpath:META-INF/config.properties" />
	<!-- 定义数据源 -->
	<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
		destroy-method="close">
		<property name="driverClass" value="${jdbc.ams.driver}" />
		<property name="jdbcUrl" value="${jdbc.ams.url}" />
		<property name="user" value="${jdbc.ams.username}" />
		<property name="password" value="${jdbc.ams.password}" />
		<property name="initialPoolSize" value="${initialSize}" />
		<property name="minPoolSize" value="${minPoolSize}" />
		<property name="maxPoolSize" value="${maxActive}" />
		<property name="acquireIncrement" value="${acquireIncrement}" />
		<property name="maxIdleTime" value="${maxIdleTime}" />
	</bean>

	<!-- 定义jdbc模板类 -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
		<property name="dataSource" ref="dataSource" />
		<property name="configLocation" value="classpath:META-INF/sqlmap/sqlmap.xml" />
	</bean>

	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="addBook" propagation="REQUIRED" />
			<tx:method name="addUserBook" propagation="MANDATORY" />
			<tx:method name="deleteBook" propagation="REQUIRES_NEW" />
			<tx:method name="addNewBook" propagation="NEVER" />
			<tx:method name="addUser" propagation="NESTED" />
		</tx:attributes>
	</tx:advice>
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>
	
</beans>

 

 

Java代码 bubuko.com,布布扣bubuko.com,布布扣

  1. @Service("bookService")  

  2. public class BookServiceImpl implements BookService {  

  3.   

  4.     private static final Logger logger      = LogManager.getLogger(BookServiceImpl.class);  

  5.     public static final String  ADD_BOOK    = "insert into t_book(id,name) values(1,‘duck-j2ee‘)";  

  6.   

  7.     public static final String  DELETE_BOOK = "delete from  t_book where id=1";  

  8.   

  9.     private JdbcTemplate        jdbcTemplate;  

  10.     @Autowired  

  11.     private BookDao             bookDao;  

  12.   

  13.     public void addBook() throws Exception {  

  14.         Book book = new Book();  

  15.         book.setName("ibatis");  

  16.         book.setPrice(11);  

  17.         bookDao.insert(book);  

  18.         throw new UnRollbackException("受检查异常,不会回滚");  

  19.     }  

  20.   

  21.     public void deleteBook(int id) {  

  22.         try {  

  23.             bookDao.deleteById(id);  

  24.         } catch (SQLException e) {  

  25.             logger.error("", e);  

  26.         }  

  27.     }  

  28.   

  29.     @LoggingRequired  

  30.     public void addNewBook(String name, int price) {  

  31.         try {  

  32.             Book book = new Book();  

  33.             book.setName(name);  

  34.             book.setPrice(price);  

  35.             bookDao.insert(book);  

  36.             List<Book> lists = bookDao.selectAll();  

  37.             System.out.println(lists);  

  38.         } catch (SQLException e) {  

  39.             logger.error("", e);  

  40.         }  

  41.     }  

  42.   

  43.     public void addUserBook() {  

  44.         jdbcTemplate.execute("insert into t_book(id,name) values(3,‘UserBook‘)");  

  45.     }  

  46.   

  47.     /** 

  48.      * Setter method for property <tt>jdbcTemplate</tt>. 

  49.      * 

  50.      * @param jdbcTemplate value to be assigned to property jdbcTemplate 

  51.      */  

  52.     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {  

  53.         this.jdbcTemplate = jdbcTemplate;  

  54.     }  

  55.   

  56.     /** 

  57.      * @see com.david.biz.service.BookService#queryAll() 

  58.      */  

  59.     public List<Book> queryAll() {  

  60.         try {  

  61.             return bookDao.selectAll();  

  62.         } catch (SQLException e) {  

  63.             logger.error("", e);  

  64.         }  

  65.         return null;  

  66.     }  

  67.   

  68. }  

@Service("bookService")
public class BookServiceImpl implements BookService {

    private static final Logger logger      = LogManager.getLogger(BookServiceImpl.class);
    public static final String  ADD_BOOK    = "insert into t_book(id,name) values(1,‘duck-j2ee‘)";

    public static final String  DELETE_BOOK = "delete from  t_book where id=1";

    private JdbcTemplate        jdbcTemplate;
    @Autowired
    private BookDao             bookDao;

    public void addBook() throws Exception {
        Book book = new Book();
        book.setName("ibatis");
        book.setPrice(11);
        bookDao.insert(book);
        throw new UnRollbackException("受检查异常,不会回滚");
    }

    public void deleteBook(int id) {
        try {
            bookDao.deleteById(id);
        } catch (SQLException e) {
            logger.error("", e);
        }
    }

    @LoggingRequired
    public void addNewBook(String name, int price) {
        try {
            Book book = new Book();
            book.setName(name);
            book.setPrice(price);
            bookDao.insert(book);
            List<Book> lists = bookDao.selectAll();
            System.out.println(lists);
        } catch (SQLException e) {
            logger.error("", e);
        }
    }

    public void addUserBook() {
        jdbcTemplate.execute("insert into t_book(id,name) values(3,‘UserBook‘)");
    }

    /**
     * Setter method for property <tt>jdbcTemplate</tt>.
     *
     * @param jdbcTemplate value to be assigned to property jdbcTemplate
     */
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    /**
     * @see com.david.biz.service.BookService#queryAll()
     */
    public List<Book> queryAll() {
        try {
            return bookDao.selectAll();
        } catch (SQLException e) {
            logger.error("", e);
        }
        return null;
    }

}

 

 

Java代码 bubuko.com,布布扣bubuko.com,布布扣

  1. /** 

  2.  * execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) 

  3.           throws-pattern?) 

  4.  *arg()  限制连接点匹配参数为指定类型的执行方法 

  5.  *@args() 限制连接点匹配参数由执行注解标注的执行 

  6.  *execution() 用于匹配连接点的执行方法 

  7.  *this() 限制连接点匹配AOP代理的Bean引用为执行类型的类 

  8.  *target() 限制连接点匹配目标对象为指定类型的类 

  9.  *@target() 限制连接点匹配特定的执行对象,这些对象应具备指定的注解类型 

  10.  *@annotation()限制匹配带有指定注解的连接点 

  11.  * 

  12.  * 

  13.  * 

  14.  * @author zhangwei_david 

  15.  * @version $Id: LogAspect.java, v 0.1 2014年11月29日 下午1:10:13 zhangwei_david Exp $ 

  16.  */  

  17. @Component  

  18. @Aspect  

  19. public class LogAspect {  

  20.     private static final Logger logger = LogManager.getLogger(LogAspect.class);  

  21.   

  22.     /** 

  23.      * 匹配参数是任何类型,任何数量 且在com,david.biz包或子包下的方法 

  24.      */  

  25.     @Pointcut("args(..)&&within(com.david.biz..*)")  

  26.     public void arg() {  

  27.   

  28.     }  

  29.   

  30.     @Pointcut("@args(com.david.aop.LoggingRequired)")  

  31.     public void annotationArgs() {  

  32.   

  33.     }  

  34.   

  35.     @Pointcut("@annotation(com.david.aop.LoggingRequired)")  

  36.     public void logRequiredPointcut() {  

  37.   

  38.     }  

  39.   

  40.     @Pointcut("args(java.lang.String,*)")  

  41.     public void argsWithString() {  

  42.   

  43.     }  

  44.   

  45.     @Pointcut("target(com.david.biz.service.impl.BookServiceImpl)")  

  46.     public void targetPointcut() {  

  47.   

  48.     }  

  49.   

  50.     @Pointcut("@target(org.springframework.stereotype.Service)")  

  51.     public void targetAnnotation() {  

  52.   

  53.     }  

  54.   

  55.     //    @Around("execution(* org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(..))")  

  56.     //    public Object aa(ProceedingJoinPoint pjp) throws Throwable {  

  57.     //        try {  

  58.     //            Object retVal = pjp.proceed();  

  59.     //            System.out.println(retVal);  

  60.     //            return retVal;  

  61.     //        } catch (Exception e) {  

  62.     //            System.out.println("异常");  

  63.     //            return null;  

  64.     //        }  

  65.     //    }  

  66.     @Before(value = "logRequiredPointcut()")  

  67.     public void before(JoinPoint joinPoint) {  

  68.         LogUtils.info(logger,  

  69.             " 连接点表达式@annotation(com.david.aop.LoggingRequired) - method={0} has been visited",  

  70.             joinPoint.getSignature().getName());  

  71.     }  

  72.   

  73.     @Before(value = "arg()")  

  74.     public void beforeArg(JoinPoint joinPoint) {  

  75.         LogUtils.info(logger,  

  76.             "连接点表达式:args(..)&&within(com.david.biz..*)  method ={0}, args ={1},target={2}",  

  77.             joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(  

  78.                 joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()  

  79.                 .getClass().getName());  

  80.     }  

  81.   

  82.     @Before(value = "argsWithString()")  

  83.     public void beforeArgWithString(JoinPoint joinPoint) {  

  84.         LogUtils.info(logger, "连接点表达式:args(java.lang.String,*)  method={0} ,args ={1},target={2}",  

  85.             joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(  

  86.                 joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()  

  87.                 .getClass().getName());  

  88.     }  

  89.   

  90.     @Before(value = "annotationArgs()")  

  91.     public void beforeAnnotationArgs(JoinPoint joinPoint) {  

  92.         LogUtils  

  93.             .info(  

  94.                 logger,  

  95.                 "连接点表达式:@args(com.david.annotation.validate.Length,*)  method={0} ,args ={1},target={2}",  

  96.                 joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(  

  97.                     joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()  

  98.                     .getClass().getName());  

  99.     }  

  100.   

  101.     @Before(value = "targetPointcut()")  

  102.     public void beforeTarget(JoinPoint joinPoint) {  

  103.         LogUtils  

  104.         .info(  

  105.             logger,  

  106.             "连接点表达式:target(com.david.biz.service.impl.BookServiceImpl)  method={0} ,args ={1},target={2}",  

  107.             joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(  

  108.                 joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()  

  109.                 .getClass().getName());  

  110.     }  

  111.   

  112.     @Before(value = " targetAnnotation()")  

  113.     public void beforeTargetAnnotation(JoinPoint joinPoint) {  

  114.         LogUtils  

  115.             .info(  

  116.                 logger,  

  117.                 "连接点表达式:@target(org.springframework.stereotype.Service)  method={0} ,args ={1},target={2}",  

  118.                 joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(  

  119.                     joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()  

  120.                     .getClass().getName());  

  121.     }  

  122. }  

/**
 * execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)
          throws-pattern?)
 *arg()  限制连接点匹配参数为指定类型的执行方法
 *@args() 限制连接点匹配参数由执行注解标注的执行
 *execution() 用于匹配连接点的执行方法
 *this() 限制连接点匹配AOP代理的Bean引用为执行类型的类
 *target() 限制连接点匹配目标对象为指定类型的类
 *@target() 限制连接点匹配特定的执行对象,这些对象应具备指定的注解类型
 *@annotation()限制匹配带有指定注解的连接点
 *
 *
 *
 * @author zhangwei_david
 * @version $Id: LogAspect.java, v 0.1 2014年11月29日 下午1:10:13 zhangwei_david Exp $
 */
@Component
@Aspect
public class LogAspect {
    private static final Logger logger = LogManager.getLogger(LogAspect.class);

    /**
     * 匹配参数是任何类型,任何数量 且在com,david.biz包或子包下的方法
     */
    @Pointcut("args(..)&&within(com.david.biz..*)")
    public void arg() {

    }

    @Pointcut("@args(com.david.aop.LoggingRequired)")
    public void annotationArgs() {

    }

    @Pointcut("@annotation(com.david.aop.LoggingRequired)")
    public void logRequiredPointcut() {

    }

    @Pointcut("args(java.lang.String,*)")
    public void argsWithString() {

    }

    @Pointcut("target(com.david.biz.service.impl.BookServiceImpl)")
    public void targetPointcut() {

    }

    @Pointcut("@target(org.springframework.stereotype.Service)")
    public void targetAnnotation() {

    }

    //    @Around("execution(* org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(..))")
    //    public Object aa(ProceedingJoinPoint pjp) throws Throwable {
    //        try {
    //            Object retVal = pjp.proceed();
    //            System.out.println(retVal);
    //            return retVal;
    //        } catch (Exception e) {
    //            System.out.println("异常");
    //            return null;
    //        }
    //    }
    @Before(value = "logRequiredPointcut()")
    public void before(JoinPoint joinPoint) {
        LogUtils.info(logger,
            " 连接点表达式@annotation(com.david.aop.LoggingRequired) - method={0} has been visited",
            joinPoint.getSignature().getName());
    }

    @Before(value = "arg()")
    public void beforeArg(JoinPoint joinPoint) {
        LogUtils.info(logger,
            "连接点表达式:args(..)&&within(com.david.biz..*)  method ={0}, args ={1},target={2}",
            joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(
                joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()
                .getClass().getName());
    }

    @Before(value = "argsWithString()")
    public void beforeArgWithString(JoinPoint joinPoint) {
        LogUtils.info(logger, "连接点表达式:args(java.lang.String,*)  method={0} ,args ={1},target={2}",
            joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(
                joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()
                .getClass().getName());
    }

    @Before(value = "annotationArgs()")
    public void beforeAnnotationArgs(JoinPoint joinPoint) {
        LogUtils
            .info(
                logger,
                "连接点表达式:@args(com.david.annotation.validate.Length,*)  method={0} ,args ={1},target={2}",
                joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(
                    joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()
                    .getClass().getName());
    }

    @Before(value = "targetPointcut()")
    public void beforeTarget(JoinPoint joinPoint) {
        LogUtils
        .info(
            logger,
            "连接点表达式:target(com.david.biz.service.impl.BookServiceImpl)  method={0} ,args ={1},target={2}",
            joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(
                joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()
                .getClass().getName());
    }

    @Before(value = " targetAnnotation()")
    public void beforeTargetAnnotation(JoinPoint joinPoint) {
        LogUtils
            .info(
                logger,
                "连接点表达式:@target(org.springframework.stereotype.Service)  method={0} ,args ={1},target={2}",
                joinPoint.getSignature().getName(), ToStringBuilder.reflectionToString(
                    joinPoint.getArgs(), ToStringStyle.SHORT_PREFIX_STYLE), joinPoint.getTarget()
                    .getClass().getName());
    }
}

 

Java代码 bubuko.com,布布扣bubuko.com,布布扣

  1. /** 

  2.  * 

  3.  * @author zhangwei_david 

  4.  * @version $Id: T.java, v 0.1 2014年12月1日 上午9:35:44 zhangwei_david Exp $ 

  5.  */  

  6. @RunWith(SpringJUnit4ClassRunner.class)  

  7. @ContextConfiguration(locations = "file:H:/workspace4study/WebApp/src/main/webapp/WEB-INF/applicationContext.xml")  

  8. public class BookServiceTest {  

  9.   

  10.     @Autowired  

  11.     private BookService bookService;  

  12.   

  13.     @Test  

  14.     public void testB() {  

  15.         bookService.addNewBook("Junit  Test"1000);  

  16.     }  

  17.   

  18. }  

/**
 *
 * @author zhangwei_david
 * @version $Id: T.java, v 0.1 2014年12月1日 上午9:35:44 zhangwei_david Exp $
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "file:H:/workspace4study/WebApp/src/main/webapp/WEB-INF/applicationContext.xml")
public class BookServiceTest {

    @Autowired
    private BookService bookService;

    @Test
    public void testB() {
        bookService.addNewBook("Junit  Test", 1000);
    }

}

 

 

Java代码 bubuko.com,布布扣bubuko.com,布布扣

  1. 2014-12-01 11:14:39  [ main:1577 ] - [ INFO ]   连接点表达式@annotation(com.david.aop.LoggingRequired) - method=addNewBook has been visited  

  2. 2014-12-01 11:14:39  [ main:1587 ] - [ INFO ]  连接点表达式:args(..)&&within(com.david.biz..*)  method =addNewBook, args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl  

  3. 2014-12-01 11:14:39  [ main:1588 ] - [ INFO ]  连接点表达式:args(java.lang.String,*)  method=addNewBook ,args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl  

  4. 2014-12-01 11:14:39  [ main:1588 ] - [ INFO ]  连接点表达式:target(com.david.biz.service.impl.BookServiceImpl)  method=addNewBook ,args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl  

  5. 2014-12-01 11:14:39  [ main:1589 ] - [ INFO ]  连接点表达式:@target(org.springframework.stereotype.Service)  method=addNewBook ,args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl  

  6. 2014-12-01 11:14:39  [ main:1589 ] - [ INFO ]  连接点表达式:args(..)&&within(com.david.biz..*)  method =insert, args =Object[][{Book[id=0,name=Junit  Test,price=1000]}],target=com.david.biz.dao.impl.BookDaoImpl  

  7. 2014-12-01 11:14:39  [ main:1590 ] - [ INFO ]  连接点表达式:@args(com.david.annotation.validate.Length,*)  method=insert ,args =Object[][{Book[id=0,name=Junit  Test,price=1000]}],target=com.david.biz.dao.impl.BookDaoImpl  

  8. 2014-12-01 11:14:39  [ main:1591 ] - [ INFO ]  连接点表达式:args(java.lang.String,*)  method=insert ,args =Object[][{demo.insert,Book[id=0,name=Junit  Test,price=1000]}],target=com.ibatis.sqlmap.engine.impl.SqlMapClientImpl  

2014-12-01 11:14:39  [ main:1577 ] - [ INFO ]   连接点表达式@annotation(com.david.aop.LoggingRequired) - method=addNewBook has been visited
2014-12-01 11:14:39  [ main:1587 ] - [ INFO ]  连接点表达式:args(..)&&within(com.david.biz..*)  method =addNewBook, args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl
2014-12-01 11:14:39  [ main:1588 ] - [ INFO ]  连接点表达式:args(java.lang.String,*)  method=addNewBook ,args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl
2014-12-01 11:14:39  [ main:1588 ] - [ INFO ]  连接点表达式:target(com.david.biz.service.impl.BookServiceImpl)  method=addNewBook ,args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl
2014-12-01 11:14:39  [ main:1589 ] - [ INFO ]  连接点表达式:@target(org.springframework.stereotype.Service)  method=addNewBook ,args =Object[][{Junit  Test,1000}],target=com.david.biz.service.impl.BookServiceImpl
2014-12-01 11:14:39  [ main:1589 ] - [ INFO ]  连接点表达式:args(..)&&within(com.david.biz..*)  method =insert, args =Object[][{Book[id=0,name=Junit  Test,price=1000]}],target=com.david.biz.dao.impl.BookDaoImpl
2014-12-01 11:14:39  [ main:1590 ] - [ INFO ]  连接点表达式:@args(com.david.annotation.validate.Length,*)  method=insert ,args =Object[][{Book[id=0,name=Junit  Test,price=1000]}],target=com.david.biz.dao.impl.BookDaoImpl
2014-12-01 11:14:39  [ main:1591 ] - [ INFO ]  连接点表达式:args(java.lang.String,*)  method=insert ,args =Object[][{demo.insert,Book[id=0,name=Junit  Test,price=1000]}],target=com.ibatis.sqlmap.engine.impl.SqlMapClientImpl

 

 

Spring Aop 切点表达式

标签:execution   target   within   表达式   连接点   

原文地址:http://jlins.blog.51cto.com/4487484/1585172

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!