mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:25:49 +00:00
add LoggingAspect
This commit is contained in:
parent
3a931080d4
commit
4d46f058c3
3 changed files with 36 additions and 6 deletions
6
pom.xml
6
pom.xml
|
@ -18,7 +18,7 @@
|
|||
<properties>
|
||||
|
||||
<!-- Generic properties -->
|
||||
<java.version>17</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<!-- Important for reproducible builds. Update using e.g. ./mvnw versions:set
|
||||
|
@ -71,6 +71,10 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- Workaround for AOT issue (https://github.com/spring-projects/spring-framework/pull/33949) -->
|
||||
<groupId>io.projectreactor</groupId>
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package org.springframework.samples.petclinic;
|
||||
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class LoggingAspect {
|
||||
|
||||
//Pointcut: all methods in package "model"
|
||||
@Before("execution(* model.BaseEntity.getId())")
|
||||
public void logBeforeMethod(){
|
||||
System.out.println("model.BaseEntity.getId...");
|
||||
}
|
||||
|
||||
@Before("execution(* model.NamedEntity.getName())")
|
||||
public void logBeforeMethod2(){
|
||||
System.out.println("model.NamedEntity.getName...");
|
||||
}
|
||||
|
||||
@Before("execution(* model.Person.*())")
|
||||
public void logBeforeMethod3(){
|
||||
System.out.println("model.Person");
|
||||
}
|
||||
}
|
|
@ -15,15 +15,14 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Simple JavaBean domain object representing a visit.
|
||||
|
|
Loading…
Reference in a new issue