Reputation: 31
I have two different methods in the same class. I get SonarLint error that
"Methods with Spring proxy should not be called via "this".
These two methods are marked with the @Transaction
annotation. Even though I made the annotations '@Transactional(propagation = Propagation.REQUIRES_NEW)
', but it didn't solve the SonarLint error. I cannot move methods to another class. What should I do?
@Transactional
public void processEmails(SearchFilter searchFilter, ExchangeService exchangeService) throws Exception
{
Folder inbox = Folder.bind(exchangeService, WellKnownFolderName.Inbox);
....
....
...
@Transactional
public void readAndProcessProposalApprovalMails() throws Exception
{
try (ExchangeService exchangeService = new MicrosoftExchangeDomainServiceImpl(exchangeUsername, encryptionService.decryptWithGCMAlgorithm(exchangePassword), exchangeServiceUrl, exchangeServiceTimeout, exchangeDomain))
{
SearchFilter searchFilter = microsoftExchangeService.getSearchFilter(false, null, approvalSubjectPrefix, null);
processEmails(searchFilter, exchangeService);
}
}
Upvotes: 1
Views: 66
Reputation: 90
To address the SonarLint error you can use one of these two solutions:
Spring uses proxies to manage transactional boundaries. and when calling the method within the same class using "this' the transactional annotation is ignored because it bypasses the proxy.
AopContext.currentProxy(): this mehtod will give you the current Spring AOP proxy for the bean, which you can use to call the methods with transactional annotations.
Upvotes: 0