我有一点问题。我在函数返回后调用AfterReturning
函数,我的AfterReturning
函数工作了两次,我不想这样做。这里是代码:AOP AfterReturning函数返回两次
@Aspect
@Component
@Configuration
public class AspectOP {
LogController logcontroller = new LogController();
@AfterReturning("execution(* com..*save*(..))")
public void doSomething() {
logcontroller.guestbook("XD");
}
}
我有2个保存功能,我们改了名字,但它又是一样的。我尝试删除@Component或@Aspect,然后它不起作用。
编辑
我保存功能
@Controller
@RequestMapping("/api")
public class EntryController {
@Autowired
EntryRepository repo;
Account account;
@RequestMapping(path = "/getir", method = RequestMethod.GET)
public @ResponseBody List<Entries> getir(){
return repo.findAll();
}
@RequestMapping(path = "/saveentry", method = RequestMethod.POST, consumes = "application/json")
public @ResponseBody Entries save(@RequestBody Entries entry) {
return repo.save(entry);
}
}
LogController.class
@Controller
public class LogController {
@MessageMapping("/guestbook")
@SendTo("/topic/entries")
public Log guestbook(String message) {
System.out.println("Received message: " + message);
return new Log(message);
}
}
我的主要目标是当事情被保存,我送点东西给我的插座。它正在工作,但是某些功能正在工作两次。
也可以显示您所期望的忠告适用于 – kuhajeyan
我添加类的类。 –