@Async in Spring doesn't work in Service class?

前端 未结 2 773
野趣味
野趣味 2021-01-20 07:33

@Async method in @Service annotated class in standalone Spring Boot application doesn\'t run asynchronously. What am I doing wrong?

When I

2条回答
  •  猫巷女王i
    2021-01-20 08:15

    Calling async method from within the same class would trigger the original method and not the intercepted one. You need to create another service with the async method, and call it from your service.

    Spring creates a proxy for each service and component you create using the common annotations. Only those proxies contain the wanted behavior defined by the method annotations such as the Async. So, calling those method not via the proxy but by the original naked class would not trigger those behaviors.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题