REST Controller 메서드를 구현했으며 구현 된 측면이 없을 때 제대로 작동합니다. 측면을 구현 한 후에도 컨트롤러 메서드는 여전히 백그라운드에서 잘 실행되지만 (즉, DELETE 요청이 실제로 항목을 삭제함) Postman으로 응답을 테스트 할 때 응답을받지 못합니다. Aspect가 작동하고 메소드가 호출되면 txt 파일이 업데이트됩니다.
@RestController
public class MovieScreeningREST {
@Autowired
private MovieScreeningService movieScreeningService;
@GetMapping("/movies")
public List<MovieScreening> findAll(){
return movieScreeningService.findAll();
}
@GetMapping("/movies/genre={movieGenre}")
public List<MovieScreening> findAllByMovieGenre(@PathVariable String movieGenre){
return movieScreeningService.findAllByMovieGenre(movieGenre);
}
@GetMapping("/movies/minimum-tickets={amount}")
public List<MovieScreening> findAllByTicketsSoldGreaterThanEqual(@PathVariable int amount){
return movieScreeningService.findAllByTicketsSoldGreaterThanEqual(amount);
}
@GetMapping("/movies/maximum-screenings={amount}")
public List<MovieScreening> findAllByScreeningsNumberLessThanEqual(@PathVariable int amount){
return movieScreeningService.findAllByScreeningsNumberLessThanEqual(amount);
}
@GetMapping("/movies/id={id}")
public MovieScreening findById(@PathVariable int id){
return movieScreeningService.findById(id);
}
@PostMapping("/movies")
public MovieScreening addMovieScreening(@RequestBody MovieScreening movieScreening){
return movieScreeningService.save(movieScreening);
}
@PutMapping("/movies")
public MovieScreening editMovieScreening(@RequestBody MovieScreening movieScreening){
return movieScreeningService.save(movieScreening);
}
@DeleteMapping("/movies/id={id}")
public String deleteMovieScreening(@PathVariable int id){
return movieScreeningService.deleteById(id);
}
}
Aspect 클래스
@EnableAspectJAutoProxy
@Aspect
@Component
public class Logger {
@Pointcut("execution(* asss.pj.projekat_bioskop.controller.*.*(..))")
public void allRESTMethods(){};
@Around("allRESTMethods()")
public void blabla(ProceedingJoinPoint pjp) {
//@Before
String methodName = pjp.getSignature().getName();
String before = "*** Attempting " + methodName + " method ***";
writeLog(before);
try {
//@AfterReturning
pjp.proceed();
String success = "\n*** Method " + methodName + " has succeeded";
writeLog(success);
} catch (Throwable throwable){
//@AfterThrowing
String failed = "\n*** Method " + methodName
+ " has failed. " + throwable.getMessage() + " .***";
writeLog(failed);
}
//@After
String after = "\n";
writeLog(after);
}
public void writeLog(String log){
File file = new File("filmovi_izvestaj.txt");
try (Writer wr = new FileWriter(file, true)){
wr.write(log);
} catch(FileNotFoundException fe){
fe.printStackTrace();
} catch(IOException ioe){
ioe.printStackTrace();
}
}
}