본문 바로가기
개발/Spring Boot

9. Annotation 설정

by 카리3 2021. 2. 12.

1. Interface 만들기

package com.kangong.common.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecutionTime {

}

2. Aspect 구현체 만들기

 @Around("@annotation(com.kangong.common.annotation.LogExecutionTime)")
		public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable{
			StopWatch stopWatch = new StopWatch();
			stopWatch.start();
			log.debug("시작================>");
			Object proceed = joinPoint.proceed();
			stopWatch.stop();
			log.debug("끝================>"+stopWatch.prettyPrint());
			System.out.println("annotation======>");
			
			return proceed;
		}

3. 사용

	@LogExecutionTime
	@GetMapping("/main")
	public String main() {				
		System.out.println("main====");
		//return "/views/common/main.jsp";
		return "common/main";
	}

'개발 > Spring Boot' 카테고리의 다른 글

11.Tag Library  (0) 2021.02.15
10.SQL Log 설정  (0) 2021.02.12
8. Spring Security 설정  (0) 2021.02.12
7.aop 설정  (0) 2021.02.11
6.thymeleaf 설정  (0) 2021.02.11