my service:
@Service
public class ForgetService{
@Async
public CompletableFuture<Object> getTokenService() {
Map<String, Object> map = new HashMap<>(8);
map.put("status", ErrorEnum.TOKEN_SUSSCESS.getStatus());
map.put("message", ErrorEnum.TOKEN_SUSSCESS.getMessage());
return CompletableFuture.completedFuture(map);
}
}
my controller:
@RestController
public class ForgetController {
private final ForgetService forgetService;
@Autowired
private ForgetController(ForgetService forgetService) {
this.forgetService = forgetService;
}
@PostMapping(value = "/forget/token")
@Async
public CompletableFuture<Object> getTokenController() {
return CompletableFuture.completedFuture(forgetService.getTokenService());
}
}
spring boot application class:
@SpringBootApplication
@EnableAsync
public class ApitestApplication {
public static void main(String[] args) {
SpringApplication.run(ApitestApplication.class, args);
}
}
when i run my application, console log :
The bean 'forgetService' could not be injected as a 'com.apitest.service.ForgetService' because it is a JDK dynamic proxy that implements: com.apitest.inf.ForgetServiceInf
Action:
Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.
i tried setting 'spring.aop.proxy-target-class=true' in application.properties and setting '@EnableAsync(proxyTargetClass=true), but it's useless,so what's wrong? how to resolve it?