【问题标题】:intellij spring boot build errorIntellij Spring Boot 构建错误
【发布时间】:2018-10-18 10:15:26
【问题描述】:

使用 IntelliJ 构建 spring-boot 应用程序时出现错误。当我在 IntelliJ 上单击“构建”时,它会给我一个错误列表,但如果我 mvn clean install,那么它会完美构建。也许有人知道这可能是错误还是配置错误?

Main.class

package com.manvydas.bachelor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Main.class, args);
    }
}

主类只有运行方法

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.manvydas</groupId>
    <artifactId>bachelor</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>manvydas-bachelor-project</name>
    <description>Manvydas bachelor project</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>

        <dependency>
            <groupId>com.nulab-inc</groupId>
            <artifactId>zxcvbn</artifactId>
            <version>1.2.3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.21</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
        </dependency>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

【问题讨论】:

  • 给我看看运行配置的截图
  • 您的工作目录是否应该是 $MODULE_DIR 而不是 $MAVEN_REPOSITORY ?
  • 你的意思是在 pom.xml 中?不,我尝试从一开始就做 2.0.1 项目
  • $MODULE_DIR 更改什么也没做。项目正在构建时发生错误,而不是运行

标签: java maven spring-boot intellij-idea


【解决方案1】:

您的 IntelliJ 配置可能有问题。但是,您可以在 IntelliJ 的终端中输入命令mvn spring-boot:run 来运行您的应用程序。

【讨论】:

    【解决方案2】:

    问题是您的 IntelliJ 工件构建没有创建与您的 Maven pom 相同的包。

    无论您使用 IntelliJ 还是 Maven 创建它,您都应该查看您的项目工件以确保最终得到完全相同的包。

    【讨论】:

      【解决方案3】:

      请记住,经过几个(错误)配置步骤后,IntelliJ 可能会进入无法再识别 Spring 的状态。我有时也有这种情况。然后只需删除缓存(文件->无效缓存...),只是索引选项对我有用。在我们的团队中,我们看到这在不同的机器(IntelliJ 2021.1、Windows 10)上多次运行。

      【讨论】:

        猜你喜欢
        • 2023-01-28
        • 2021-07-08
        • 2021-11-01
        • 2017-11-20
        • 2018-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-22
        相关资源
        最近更新 更多