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:
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of AOP annotations in automatic assembly notice

  • Hibernate Inteceptor

    The end of the project stage, the client suddenly put forward a very troublesome but normal demand, the system records all changes must be carried out. Formats such as: 2004.1.1 12:30 Ikuya wind orders Sales Order Date 2004.1.2-> 2004.1.3 The firs ...

  • log4j easy application in java

    JAVA development, frequently used the log output, in a so-called most of the software company will have its own set of configuration style, re-read the configuration file to initialize property of the log, it will be good, but sometimes may not need to fu

  • jboss ejb3 Message Driven Bean

    Super Medium ejb hate. . . . . . . . . . . . . . . . . . . ================================================ To configure a Message Driven Bean in a different application server parameters are not the same. Currently only passed the test jboss. Message Dri

  • hibernate call stored procedure

    hibernate call stored procedure

  • myeclipse plugin

    myeclipsePlug-ins? 1.tomcatPlugin(Start tomcat ):http ://www.sysdeo.com/eclipse/tomcatPlugin.html,2.xVersions of eclipse 3 version 2 .1Version doesn't work. 2.Lomboz(Development of jsp program ,jspDynamic prompt, debugging ):http://forge.objectweb.org/pro

  • hibernate generic generic DAO

    package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *

  • First Hibernate Example

    Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useless lazy loading. UserDAOImpl category code, and other co

  • Struts2 + hibernate + spring problem user log in

    dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries