AOP annotations in automatic assembly notice

AOP annotations in automatic assembly notice

First, create an annotated class:

Note: aop introduction

package cn.csdn.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
public class ServiceImpl implements Service {

        /**
         * @Before("execution(* work())") The first parameter in the method "*" Is a return value, the second parameter "work()" Is the method name
         * */
        @Before("execution(* goWork())")
        public void eat(JoinPoint jp) {
                // TODO Auto-generated method stub
                System.out.println("I'm eating!!!");
                /*
                 *  Output is the result of : I'm eating!!!  I'm working !
                 */
        }

        /**
         * After(execution(*
         * cn.csdn.service.Emp*.*(..))) First parameter method (*) Is a return value, the second parameter is located in cn.csdn.service
         *  All package prefix is under Emp class methods ,((..)) Represents the method argument can be of variable parameters
         * */
        @After("execution(* cn.csdn.service.Emp*.*(..))")
        public void goCompany() {
                // TODO Auto-generated method stub
                System.out.println("I want to go home");
        }
/**
 *  Summary of the return value is void and * Two types of representation of the method name directly write method name . Write which method of that class or the class and method name fuzzy match */
        @AfterThrowing(pointcut = "execution(* *..EmpService*.*(..))", throwing = "ex")
        public void leave(Exception ex) {
                // TODO Auto-generated method stub
                System.out.println("I want leav");
        }

        @Before("execution(* cn.csdn.service.EmpServiceImpl.*(..))")
        public void goHome() {
                // TODO Auto-generated method stub
                System.out.println("I want go Home");

        }

        @Around("execution(* *..Emp*.goWork(..))")
        public void signIn() {
                // TODO Auto-generated method stub
                System.out.println("I around before");
                System.out.println("I around after");

        }

}

The part of the xml code:

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"
         >

        <bean/>
        <bean></bean>
        <aop:aspectj-autoproxy/>

</beans>

source code is as follows:

分类:Java 时间:2011-05-08 人气:263
分享到:
blog comments powered by Disqus

相关文章

  • public void testStatementAddBatch () public void testConnCommit () 2011-09-01

    public void testStatementAddBatch() { Connection conn = null; Statement stmt = null; try { conn = getDBConnectionMsSqlBySuperAdmin(); stmt = conn.createStatement(); for(int i = 0; i < 100; i++) { String sql = " sql " + i; stmt.addBatch(sql); } stm

  • Spring Annotations Learning Letters (1) build a simple Web application 2010-08-04

    This series of study notes are derived from Daniel's blog: http://snowolf.javaeye.com/blog/577989 Recent work has changed, it is necessary to learn about the Spring annotation! Found some examples, more general, soil, mostly reprinted excerpt, follow

  • Configuration Spring 2.5 annotations 2010-06-30

    Introduction From the beginning of the birth, Spring framework to adhere to its purpose: streamlining enterprise application development, complex problems simultaneously to provide a strong, non-invasive solution. Spring2.0 released a year ago, put these

  • Some rights java modifiers, private / friendly / protected / public 2010-05-29

    Begin testing the following: A Test class, as was access to the class, private not say, can access only its own, public is able to access, this is mainly to distinguish between friendly and protected New two classes, Test1 and Test2 to visit Test, Te ...

  • Hibernate 3.4 in the two questions 2009-05-20

    Long time no use hibernate, and because of their want to be a small thing, thought, ready to use the latest packages. Each package with the new series will be very annoying, how can this exception? ? ? 3.4 is pretty frustrating under me. 1 slf4j when the

  • struts2 command pattern example 2010-04-26

    struts2 beginning, and there is no distinction between webwork, and thought, or look webwork bar, webwork is based on xwork, but xwork exist independently of webcontainer, then start from xwork. xwork is to build and command mode. For the command mod ...

  • Introduced the use of Spring 2010-09-14

    Reference to "Spring Advanced Programming" Spring AOP is provided by the introduction of an important part of functionality. Use the introduction to the existing object dynamically add new features. When we add in the existing objects in th

  • Common abnormalities resolved 2011-09-18

    ConcurrentHashMap and CopyOnWriteArrayList comparison. Blog categories: Java ConcurrentHashMap ConcurrentHashMap introduced Segment, each Segment is a hashtable, the equivalent of two Hash table, and then lock in the Segment level, and increased concurren

  • Java Swing中的JButton.JComboBox.JList和JColorChooser组件使用案例 2014-07-24

    这篇文章主要介绍了Java Swing中的按钮(JButton)、组合框(JComboBox)、下拉列表(JList)和颜色选择器(JColorChooser)组件使用案例,需要的朋友可以参考下 Swing 的组件与AWT 组件相似,但又为每一个组件增添了新的方法,并提供了更多的高级组件. Swing 的基本组件: 1.按钮(JButton): Swing 中的按钮可以显示图像,并且可以将按钮设置为窗口的默认图标,而且还可以将多个图像指定给一个按钮。 (1).JButton 常用的构造方法。 J

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.129 (s). 12 q(s)