1. Add the JAR package and generate some dependent Jar packages for the JAR package of Spring, otherwise ClassNotFound will be reported.
Student. java
package com.lubby.bean;import org.springframework.stereotype.Component;@Component("student")public class Student {private String id;private String name;public Student() {super();}public Student(String id, String name) {super();this.id = id;this.name = name;}public void readBook() {System.out.println("I am reading book now.....");}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}}
Something. java
package com.lubby.bean;import org.springframework.stereotype.Component;@Component("something")public class Something {public void borrowBook() {System.out.println("Borrow the book from library......");}public void returnBook() {System.out.println("Return the book to library........");}}
Test. xml
Aspect ref = "something"> --- execute the borrowBook method before running the readBook Method
Execution result
Borrow the book from library......I am reading book now.....Return the book to library........