[英]Why can I start my application using mvn spring-boot:run while IntelliJ run doen´t work?
When I use the command mvn spring-boot:run the project compiles and starts perfectly.当我使用命令 mvn spring-boot:run 时,项目编译并完美启动。 However, when I use the play-button in my IDE (IntelliJ), I get the following error:但是,当我在 IDE (IntelliJ) 中使用播放按钮时,出现以下错误:
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.我很乐意使用 IDE 提供的调试和开发工具。
What I 've tried:我试过的:
My pom.xml我的 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.非常感谢帮助。
You need to add org.springframework.mail.javamail.JavaMailSender.jar
as dependency as it is missing.您需要添加org.springframework.mail.javamail.JavaMailSender.jar
作为依赖项,因为它丢失了。 You may follow the following steps to fix in intellij.您可以按照以下步骤修复 intellij。
Now, it will be fixed.现在,它将被修复。
You need to create Configuration class and tell them to container with @Bean
I just tried.您需要创建 Configuration 类并告诉他们使用我刚刚尝试过的@Bean
进行容器。 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 https://gist.github.com/thangavel-projects/9c30e6fe141755cf471c9d574e7341b2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.