简体   繁体   English

为什么我可以使用 mvn spring-boot:run 启动我的应用程序而 IntelliJ run 不起作用?

[英]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:我试过的:

  • Select Build->Rebuild Project选择 Build->Rebuild Project
  • Clicking File>Invalidate caches/ restart单击文件>使缓存无效/重新启动
  • mvn clean -> Build -> Make Project mvn clean -> Build -> Make Project
  • Maven -> Reimport Maven -> 重新导入
  • Checked that there is no excludes in Preferences |检查首选项中没有排除项 | Build, Execution, Deployment |构建、执行、部署 | Compiler |编译器 | Excludes不包括

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。

  1. Download the jar file.下载jar文件。
  2. In IntelliJ Idea IDE, Go to File > Project Structure.在 IntelliJ Idea IDE 中,转到文件 > 项目结构。
  3. Select Modules.选择模块。
  4. In the dependecies section, select (+) icon > Select JARs or Directories在依赖项部分,选择 (+) 图标 > 选择 JAR 或目录
  5. Paste link to the location of the JAR file将链接粘贴到 JAR 文件的位置
  6. Select OK and Apply选择确定并应用

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.

相关问题 mvn spring-boot:run 不启动 spring - mvn spring-boot:run doesn't start spring 使用&#39;mvn spring-boot:run&#39;启动JavaFX Spring项目 - Start JavaFX Spring project with 'mvn spring-boot:run' 无法使用mvn spring-boot:run与Tomcat运行spring guide(问候)— getVirtualServerName NoSuchMethodError - Can not run spring guide (greeting) with Tomcat using mvn spring-boot:run — getVirtualServerName NoSuchMethodError 我可以运行我的 Spring-boot 应用程序无法调试而不是运行抛出无效参数名称“” - I can run my Spring-boot application can't debug instead of run is throws Invalid parameter name “” "终止 mvn spring-boot:run 不会停止 tomcat" - Terminating mvn spring-boot:run doesn't stop tomcat 为什么 springboot 应用程序立即从 IDEA 停止但与 mvn spring-boot:run 一起使用 - Why springboot application stops immediately from IDEA but works with mvn spring-boot:run Spring-Maven 应用程序无法执行“mvn spring-boot:run” - Spring-Maven app can't execute "mvn spring-boot:run" 替换为mvn spring-boot:run - Alternate to mvn spring-boot:run 如何将“mvn spring-boot:run”重命名为“mvn someName:run”? - How rename "mvn spring-boot:run" to "mvn someName:run"? 是否需要在 mvn spring-boot:run 之前进行 mvn 全新安装 - is it required to mvn clean install before mvn spring-boot:run
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM