๐ฅ AOP๊ฐ ํ์ํ ์ํฉ?
- ๋ชจ๋ ๋ฉ์๋์ ํธ์ถ ์๊ฐ์ ์ธก์ ํ๊ณ ์ถ๋ค๋ฉด?
- ๊ณตํต ๊ด์ฌ์ฌํญ(ํธ์ถ ์๊ฐ) vs ํต์ฌ ๊ด์ฌ์ฌํญ (๋น์ฆ๋์ค ๋ก์ง)
- ํ์ ๊ฐ์ ์๊ฐ, ํ์ ์กฐํ ์๊ฐ์ ์ธก์ ํ๊ณ ์ถ๋ค๋ฉด?
์๊ฐ ์ธก์ ํ๋ ๋ก์ง๊ณผ ํต์ฌ ๋น์ฆ๋์ค ๋ก์ง์ด ์์ด๋ฉด ์ ์ง๋ณด์๊ฐ ์ด๋ ต๋ค. > ๋๊ฐ๋ฅผ ๋ถ๋ฆฌํด์ผ ํ๋ค. > AOP (Aspect Oriented Programming)
๐ฅ AOP
์๊ฐ ์ธก์ ๋ก์ง์ ์ง๋๊ณ ์ํ๋ ๊ณณ์ ๊ณตํต ๊ด์ฌ์ฌํญ(์๊ฐ ์ธก์ ๋ก์ง) ์ ์ฉ ํ๋ฉด ๋๊ฒ ๋ค.
TimeTraceAop ๋ผ๋ ํด๋์ค๋ฅผ ๋ง๋ค๊ณ ์์ Aspect ์ด๋ ธํ ์ด์ ์ ์ด๋ค.
๊ทธ๋ฆฌ๊ณ ์คํ๋ง bean์ ๋ฑ๋กํด์ค๋ค.
๋น๋ํ ๋ ์๋ฌ๊ฐ ๋ฌ๋ค๋ฉด SpringConfig์์ ๋น์ ๋ฑ๋กํ์ง ๋ง๊ณ TimeTraceAop์์ ์๋จ์ Component ์ด๋ ธํ ์ด์ ์ ์ถ๊ฐํด์ค๋ค.
Around ์ด๋ ธํ ์ด์ ์ ํตํด์ ์ด๋์ ๊ณตํต ๊ด์ฌ ์ฌํญ์ ์ ์ฉํ ์ง ์ ํด์ค๋ค.
hello ํจํค์ง ์์ hellospring ํจํค์ง ์์ ์๋ ํด๋์ค๋ค์ ์ ์ฉํด์ค๋ค๋ ์๋ฏธ์ด๋ค.
์ต์ข ์ฝ๋
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package hello.hellospring.aop;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class TimeTraceAop {
@Around("execution(* hello.hellospring..*(..))")
public Object execut(ProceedingJoinPoint joinPoint) throws Throwable{
long start=System.currentTimeMillis();
System.out.println("start: "+joinPoint.toString());
try{
return joinPoint.proceed();
}finally{
long finish=System.currentTimeMillis();
long timeMs=finish-start;
System.out.println("end: "+joinPoint.toString()+" "+timeMs+"ms");
}
}
}
|
cs |
'Springboot > lecture' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Springboot] ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ (1) | 2022.10.05 |
---|---|
[jdbc] Row Mapper๋ ?? (0) | 2022.08.06 |
[springboot] ๊ธฐ๋ณธ์ ์ธ ๊ฐ๋ ์ ๋ฆฌ (0) | 2022.08.05 |
[springboot] ์น mvc๊ฐ๋ฐ (0) | 2022.08.02 |
[springboot] ์คํ๋ง ๋น๊ณผ ์์กด๊ด๊ณ (0) | 2022.08.02 |