A simple spring AOP example of the traditional approach

Source: Internet
Author: User
Tags aop

       After this period of study and use of spring, slowly realize the excellent spring, is deeply absorbing the essence of spring, hehe. This is just a simple AOP example, including a pre-notification, a post-notification, a surround notification, and a target object. The main goal of this example is to make it easier to get started with AOP and to find out how to configure the stuff in AOP.
Interface for target object: Istudent.java  1/**
 2 * 
 3 */
 4 package   Com.dragon.study;
 5
 6/**
 7 *  @author  dragon
 8 *
 9 */
Public   Interface  IStudent  {
11    
12    public  void addstudent (String name);


Target class: Studentimpl.java 1/**
2 *
3 */
4 Package Com.dragon.study.Impl;
5
6 Import com.dragon.study.IStudent;
7
8/**
9 * @author Dragon
10 *
11 */
public class Studentimpl implements Istudent {
13
public void Addstudent (String name) {
System.out.println ("Welcome" +name+ "You join the Spring family!");
16}
17}
18



Pre-notification: Beforeadvice.java 1/**
2 *
3 */
4 Package Com.dragon.Advice;
5
6 Import Java.lang.reflect.Method;
7
8 Import Org.springframework.aop.MethodBeforeAdvice;
9
10/**
* @author Dragon
12 *
13 */
public class Beforeadvice implements Methodbeforeadvice {
15
+ public void before (Method method,object[] args, Object target)
Throws throwable{
18
System.out.println ("This is the Before method of the Beforeadvice class.");
20
21}
22}
23
Post notification: Afteradvice.java
1/**
2 *
3 */
4 Package Com.dragon.Advice;
5
6 Import Java.lang.reflect.Method;
7
8 Import Org.springframework.aop.AfterReturningAdvice;
9
10/**
* @author Dragon
12 *
13 */
public class Afteradvice implements Afterreturningadvice {
15
public void

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.