From 438bc0a8948adefaf0de9ea5da2c9f9ff6b04a0e Mon Sep 17 00:00:00 2001 From: Quentin Date: Sat, 28 Oct 2023 16:56:56 +0200 Subject: [PATCH] Sonar: Call async methods via an injected dependency instead of directly via 'this' (use Autowired & Lazy) --- .../src/main/java/_package_/service/MailService.java.ejs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/generators/server/templates/src/main/java/_package_/service/MailService.java.ejs b/generators/server/templates/src/main/java/_package_/service/MailService.java.ejs index 436e9fb73e7c..85f030a536e3 100644 --- a/generators/server/templates/src/main/java/_package_/service/MailService.java.ejs +++ b/generators/server/templates/src/main/java/_package_/service/MailService.java.ejs @@ -29,7 +29,9 @@ import jakarta.mail.internet.MimeMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; +import org.springframework.context.annotation.Lazy; import org.springframework.mail.MailException; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; @@ -60,7 +62,9 @@ public class MailService { private final SpringTemplateEngine templateEngine; - private final MailService self; + @Autowired + @Lazy + private MailService self; public MailService(JHipsterProperties jHipsterProperties, JavaMailSender javaMailSender, MessageSource messageSource, SpringTemplateEngine templateEngine) { @@ -69,7 +73,6 @@ public class MailService { this.javaMailSender = javaMailSender; this.messageSource = messageSource; this.templateEngine = templateEngine; - this.self = this; } @Async