簡體   English   中英

AOP AfterReturning函數返回兩次

[英]AOP AfterReturning function returns twice

我有一點問題。 我在一些函數返回后調用AfterReturning函數,我的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);
    }
}

我的主要目標是在保存某些東西時,我將一些東西發送到我的插座。 它正在工作,但doSomething功能正在工作兩次。

似乎建議也適用於您的EntryRepository類。 將切入點表達式更改為類似的,僅應用於EntryController的save方法

@AfterReturning("execution(* com.xyz.EntryController.save*(..))")

這里的例子

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM