mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-24 00:05:48 +00:00
스프링 @AOP
This commit is contained in:
parent
ca16de580a
commit
19d1854e97
3 changed files with 39 additions and 0 deletions
|
@ -0,0 +1,29 @@
|
|||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
@Component
|
||||
@Aspect
|
||||
public class LogAspect {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(LogAspect.class);
|
||||
|
||||
@Around("@annotation(LogExecutionTime)")
|
||||
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
|
||||
Object proceed = joinPoint.proceed();
|
||||
|
||||
stopWatch.stop();
|
||||
logger.info(stopWatch.prettyPrint());
|
||||
|
||||
return proceed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
public @interface LogExecutionTime {
|
||||
}
|
|
@ -51,6 +51,7 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@GetMapping("/owners/new")
|
||||
@LogExecutionTime
|
||||
public String initCreationForm(Map<String, Object> model) {
|
||||
Owner owner = new Owner();
|
||||
model.put("owner", owner);
|
||||
|
@ -58,6 +59,7 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@PostMapping("/owners/new")
|
||||
@LogExecutionTime
|
||||
public String processCreationForm(@Valid Owner owner, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||
|
@ -69,12 +71,14 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@GetMapping("/owners/find")
|
||||
@LogExecutionTime
|
||||
public String initFindForm(Map<String, Object> model) {
|
||||
model.put("owner", new Owner());
|
||||
return "owners/findOwners";
|
||||
}
|
||||
|
||||
@GetMapping("/owners")
|
||||
@LogExecutionTime
|
||||
public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) {
|
||||
|
||||
// allow parameterless GET request for /owners to return all records
|
||||
|
@ -102,6 +106,7 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@GetMapping("/owners/{ownerId}/edit")
|
||||
@LogExecutionTime
|
||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||
Owner owner = this.owners.findById(ownerId);
|
||||
model.addAttribute(owner);
|
||||
|
@ -109,6 +114,7 @@ class OwnerController {
|
|||
}
|
||||
|
||||
@PostMapping("/owners/{ownerId}/edit")
|
||||
@LogExecutionTime
|
||||
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result,
|
||||
@PathVariable("ownerId") int ownerId) {
|
||||
if (result.hasErrors()) {
|
||||
|
|
Loading…
Reference in a new issue