Intellij show red underline.
and When I mouseover to red underline, that show this message.
Methods annotated with '@Async' must be overridable
Reports the cases when your code prevents a class from being subclassed by some framework (e.g. Spring or Hibernate) at runtime
What I should do for remove this error?
And It show red underline. but It still working without compile error.
I'm using Intellij 2017.2.5.
@Async
private void deleteFile(String fileName, String path) {
BasicAWSCredentials credentials = new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY);
AmazonS3 s3client = AmazonS3ClientBuilder.standard().withRegion("ap-northeast-2").withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
try {
s3client.deleteObject(new DeleteObjectRequest(AWS_BUCKET_NAME, path + fileName));
} catch (AmazonServiceException ase) {
System.out.println("Caught an AmazonServiceException.");
System.out.println("Error Message: " + ase.getMessage());
System.out.println("HTTP Status Code: " + ase.getStatusCode());
System.out.println("AWS Error Code: " + ase.getErrorCode());
System.out.println("Error Type: " + ase.getErrorType());
System.out.println("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
System.out.println("Caught an AmazonClientException.");
System.out.println("Error Message: " + ace.getMessage());
}
}
@Async is an indication to Spring to execute this method asynchronously. So it can only work on several conditions :
For the latter, it seems like you are calling this method directly in your class, so Spring has no way to know that you called this method, it's not htat magic.
You should refactor your code so the method is called on a bean managed by Spring as following code :
@Service
public class AsyncService {
@Async
public void executeThisAsync() {...}
}
@Service
public class MainService {
@Inject
private AsyncService asyncService;
public mainMethod() {
...
// This will be called asynchronusly
asyncService.executeThisAsync();
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With