add LoggingAspect

This commit is contained in:
0samsung0 2025-05-19 17:35:02 +03:00
parent 3a931080d4
commit 4d46f058c3
3 changed files with 36 additions and 6 deletions

View file

@ -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>

View file

@ -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");
}
}

View file

@ -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.