pom.xml에 의존성 추가
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.3.25</version>
</dependency>
AopProc.java
@Aspect
public class AopProc {
// @Around("within(mul.cam.a.controller.*) or within(mul.cam.a.dao.*.*)")
@Around("within(mul.cam.a.controller.*)")
public Object loggerAop(ProceedingJoinPoint joinpoint) throws Throwable{
// logger
String signatureStr = joinpoint.getSignature().toShortString();
try {
Object obj = joinpoint.proceed(); // 실행시
System.out.println("AOP log:" + signatureStr + " 메소드 실행 " + new Date());
return obj;
}finally {
// System.out.println("실행후 : " +System.currentTimeMillis());
}
}
}
@Aspect
public class AopProc {
// @Around("within(mul.cam.a.controller.*) or within(mul.cam.a.dao.*.*)")
@Around("within(mul.cam.a.controller.*)")
public Object loggerAop(ProceedingJoinPoint joinpoint) throws Throwable{
// session check
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
if(request != null) {
HttpSession session = request.getSession();
MemberDto login = (MemberDto)session.getAttribute("login");
if(login == null) {
return "redirect:/sessionOut.do";
}
}
}
}