spring maven项目中不存在自定义包

kzmpq1sx  于 2022-12-26  发布在  Spring
关注(0)|答案(1)|浏览(174)

到现在我已经在做一个更大的项目大概一个月了,是一个多模块的maven/java项目,到目前为止,我已经有过好几次这样的“错误”,但是在尝试了几次启动应用程序之后,我都成功的解决了,直到现在,我还以为是我的IntelliJ Idea中的bug,昨天,同样的问题再次发生在我身上,无论我尝试启动应用程序多少次,同样的错误一次又一次地发生在我身上。
生成应用程序时出错:
这是我看到的第一个错误行:

package com.marketcruiser.common.entity does not exist

当我展开错误时:

[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ market-cruiser-back-end ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 23 source files to D:\programiranje\JAVA\Spring Projects\market-cruiser-project\market-cruiser-web-parent\market-cruiser-back-end\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserServiceImpl.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserServiceImpl.java:[4,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserService.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserService.java:[4,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserRepository.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserRepository.java:[11,55] cannot find symbol
  symbol: class User
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/RoleRepository.java:[3,39] package com.marketcruiser.common.entity does not exist
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/RoleRepository.java:[8,55] cannot find symbol
  symbol: class Role
[ERROR] /D:/programiranje/JAVA/Spring Projects/market-cruiser-project/market-cruiser-web-parent/market-cruiser-back-end/src/main/java/com/marketcruiser/admin/user/UserServiceImpl.java:[37,12] cannot find symbol

100多行这样的错误代码。
我的项目架构是:

market-cruiser-project -> market-cruiser-common
                       -> market-cruiser-web-parent -> market-cruiser-back-end
                                                    -> market-cruiser-front-end

这是market-cruiser-project的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.marketcruiser</groupId>
    <artifactId>market-cruiser-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>market-cruiser-project</name>
    <description>Root project</description>

    <modules>
        <module>market-cruiser-common</module>
        <module>market-cruiser-web-parent</module>
    </modules>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

</project>

market-cruiser-common的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.marketcruiser</groupId>
    <artifactId>market-cruiser-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>market-cruiser-common</name>
    <description>common library</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

market-cruiser-web-parent的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.marketcruiser</groupId>
    <artifactId>market-cruiser-web-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <name>market-cruiser-web-parent</name>
    <description>parent spring web project</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <modules>
        <module>market-cruiser-back-end</module>
        <module>market-cruiser-front-end</module>
    </modules>

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

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

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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-web</artifactId>
        </dependency>

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

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>4.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.4.1</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator-core</artifactId>
        </dependency>

        <dependency>
            <groupId>com.marketcruiser</groupId>
            <artifactId>market-cruiser-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

market-cruiser-back-end的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.marketcruiser</groupId>
        <artifactId>market-cruiser-web-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>market-cruiser-back-end</artifactId>
    <name>market-cruiser-back-end</name>
    <description>market cruiser admin project</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>net.sf.supercsv</groupId>
            <artifactId>super-csv</artifactId>
            <version>2.4.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>

        <dependency>
            <groupId>com.github.librepdf</groupId>
            <artifactId>openpdf</artifactId>
            <version>1.3.8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>9</source>
                    <target>9</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

以及market-cruiser-front-end的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.marketcruiser</groupId>
        <artifactId>market-cruiser-web-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>market-cruiser-front-end</artifactId>
    <name>market-cruiser-front-end</name>
    <description>market-cruiser-front-end</description>

    <properties>
        <java.version>17</java.version>
    </properties>

    <dependencies>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

有人知道如何解决这个问题吗?
为了解决这个问题,我尝试做了什么:
1.我在SpringBoot应用程序中使用了@EntityScan({"com.marketcruiser.common.entity", "com.marketcruiser.admin.user"})
1.我更新了pom.xml到Java版本安装在我的电脑上.
1.我试着重建了好几次应用程序。

yc0p9oo0

yc0p9oo01#

在您当前的设置中,market-cruiser-commonmarket-cruiser-web-parent是两个完全独立的项目,没有任何共同之处。您当前的结构不是您所想的那样,而是这样的:

market-cruiser-project
market-cruiser-common
market-cruiser-web-parent -> market-cruiser-back-end
                          -> market-cruiser-front-end

market-cruiser-commonmarket-cruiser-web-parent应该使用market-cruiser-project作为父对象,而不是spring-boot-starter-parentspring-boot-starter-parent应该是market-cruiser-project的父对象,这样就得到了想要的结构。

相关问题