This is main application class:
@EnableAsync(proxyTargetClass = true)
@EnableDiscoveryClient
@SpringBootApplication
public class ProductApplication {
public static void main(final String[] args) {
SpringApplication.run(ProductApplication.class, args);
}
@Bean("threadPoolTaskExecutor")
public TaskExecutor getAsyncExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(20);
executor.setMaxPoolSize(1000);
executor.setWaitForTasksToCompleteOnShutdown(true);
executor.setThreadNamePrefix("Async-");
return executor;
}
}
This is service class:
@Component
public class ProductServiceImpl implements ProductService {
@Autowired
ProductRepository productRepository;
@Autowired
private ProductHandler productHandler;
@Async
@Override
public List<String> getAllCategories() {
final List<String> finalList = new ArrayList<>();
return finalList;
}
}
This is the controller class:
@RestController
public class ProductResource {
@Autowired
private ProductServiceImpl productServiceImpl;
@GetMapping("/categories")
public ResponseEntity<List<String>> getAllCategories() {
return new ResponseEntity<>(this.productServiceImpl.getAllCategories(), HttpStatus.OK);
}
}
I have annotated the service implementation method with @Async
but I get this error:
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.
If I try annotating the controller I get empty response to my get request. I have try every thing including setting proxyTargetClass
to true.
ProductService
interface or start using it by usingProductService
instead ofProductserviceImpl
in your controller. – M. Deinum