Reputation: 328
When I use the command mvn spring-boot:run the project compiles and starts perfectly. However, when I use the play-button in my IDE (IntelliJ), I get the following error:
Description:
Parameter 3 of constructor in com.example.module.services.PdfService required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
What might be the reason for this? I`d love to use the debugging and dev tools provided by the IDE.
What I 've tried:
My pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
The Service in which the error occurs
@Service
public class PdfService {
private final Logger logger = LoggerFactory.getLogger(PdfService.class);
private PdfCreator pdfCreator;
private ConfigProperties properties;
private ReceiptService receiptService;
private JavaMailSender javaMailSender;
private MessageSourceAccessor messageSourceAccessor;
@Autowired
public PdfService(PdfCreator pdfCreator,
ConfigProperties properties,
ReceiptService receiptService,
JavaMailSender javaMailSender,
MessageSourceAccessor messageSourceAccessor) {
this.pdfCreator = pdfCreator;
this.properties = properties;
this.receiptService = receiptService;
this.javaMailSender = javaMailSender;
this.messageSourceAccessor = messageSourceAccessor;
}
Help is very much appreciated.
Upvotes: 1
Views: 1125
Reputation: 939
You need to create Configuration class and tell them to container with @Bean
I just tried. It works for me.
@Configuration
public class AppConfiguration {
@Bean
public JavaMailSender javaMailSender(){
return new JavaMailSenderImpl();
}
}
Please check my Gist on the below url,
https://gist.github.com/thangavel-projects/9c30e6fe141755cf471c9d574e7341b2
Upvotes: 0
Reputation: 480
You need to add org.springframework.mail.javamail.JavaMailSender.jar
as dependency as it is missing. You may follow the following steps to fix in intellij.
Now, it will be fixed.
Upvotes: 1