java intellij Spring Boot 构建错误

jhkqcmku  于 2022-12-28  发布在  Java
关注(0)|答案(4)|浏览(159)

我在用IntelliJ构建Spring启动应用程序时出错。当我在IntelliJ上单击"Build"时,它给了我一个错误列表,但如果我使用干净安装,它会完美地构建。也许有人知道这可能是一个bug或错误的配置?

    • 主类**
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);
    }
}

主类只有run方法

    • 聚合物. 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>
laximzn5

laximzn51#

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

mgdq6dx1

mgdq6dx12#

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

rbl8hiat

rbl8hiat3#

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

sr4lhrrt

sr4lhrrt4#

我有完全相同的错误。我创建了一个新的项目由书的Spring Boot (仅使用web-starter)。我没有添加任何代码,并在创建后立即调用了它。我成功地使用了mvn干净安装(jar运行且可操作),而是智能调用(涉及自己的intellij构建步骤)由于缺少org.springframework. Boot 包而失败。(从图中可以看出,包是intellij可以识别的,只是构建步骤的问题)
我在所有无效缓存的尝试之后;重新启动的intellij;我已经完全重新安装了intellij,并升级到最新的2022.3终极版本。运行在windows 11上的java 17(尽可能多的问题);我已经把我的项目发送给了其他队友,它在他们的机器上完美地工作(正如预期的那样)。x1c 0d1x
看起来在我的intellij配置上有东西被挂起并破坏了,“build”的步骤无法与maven的工件对齐

相关问题