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;

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=""



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);

  • 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 t

  • 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 the fun

  • 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 conc

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

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

  • 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

  • spring, struts2, hibernate integration 2009-07-28

    Three configuration files: strtus.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "

  • UserType simple to use 2010-03-29

    Is now developing a small project, of which there is a need to save the data in previous years, year one data, according to the former would have been used to make a point to the main table from the table. But I do not want to do this, I analyzed a b

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 黔ICP备15002463号-1

processed in 0.205 (s). 10 q(s)