오늘의 키워드
- Spring Boot
- REST API
- Logging
- AOP (Aspect-Oriented Programming)
오늘의 내용
- AOP를 사용해 메서드 실행시간을 측정
- 코드를 입력받고 실행시키는 Controller 구현
//예시코드
@RestController
public class CodeExecutionController {
@PostMapping("/execute")
public ResponseEntity<String> executeCode(@RequestBody String code) {
String result = runCode(code);
return ResponseEntity.ok(result);
}
private String runCode(String code) {
return "Executed: " + code;
}
}
- AOP를 사용해 코드 실행 메서드의 실행 시간을 측정
@Aspect
@Component
public class ExecutionTimeAdvice {
private static final Logger logger = LoggerFactory.getLogger(ExecutionTimeAdvice.class);
@Around("@annotation(org.springframework.web.bind.annotation.PostMapping) && execution(* com.example.demo..*(..))")
public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long executionTime = System.currentTimeMillis() - start;
logger.info(joinPoint.getSignature() + " executed in " + executionTime + "ms");
return proceed;
}
}
오늘의 회고
최종프로젝트를 내부회의를 거쳐서 초반 작업을 시작했는데 튜터님의 피드백으로 너무 단순한 로직만 있는 거 같다는 의견이 있어 새로운 아이디어를 받아 팀원들과 회의 끝에 도입하고 어떤 방식으로 진행할지 결정되었는데 잘 되겠지 어떤 프로젝트인지는 아직 올리면 안 될 거 같다
'TIL' 카테고리의 다른 글
TIL내일배움캠프 try-with-resources (0) | 2024.07.29 |
---|---|
TIL내일배움캠프 15주차 Spring Scheduler (2) | 2024.07.23 |
TIL내일배움캠프 14주차 최종프로젝트 실시간 채팅 (0) | 2024.07.19 |
TIL내일배움캠프 14주차 KPT 회고 (0) | 2024.07.16 |
TIL내일배움캠프 13주차 Spring Boot와 React 통합 (0) | 2024.07.13 |