为什么 maven 模块无法识别 Java 和 Spring?

问题描述

我在 java/maven 中的模块化有一个很大的问题,我只想有 2 个可以相互交互的模块,web - web 层,端点,rest 等,存储​​ - 连接到 mongodb,来自 web 层的请求。我用 maven 创建了一个新项目,通过选择 Spring Initializer 等向其中添加模块。现在我无法运行它们,intelliJ 无法识别文件、注释等。当我尝试设置运行配置时,有如下内容:>

enter image description here

另外,正如你在下面看到的,java 包不再是 java 的了:

enter image description here

是的,我知道您会怎么想 - 更改项目结构并选择源文件夹,不,这也不起作用:

enter image description here

当我添加这些模块时,它们的 pom.xml 被忽略了(我不得不忽略它们)。有我的主要 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>org.example</groupId>
    <artifactId>MediaHosting</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

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

    <modules>
        <module>storage</module>
        <module>web</module>
    </modules>

</project>

还有一个子 pom.xml:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>mr.fisherman</groupId>
    <artifactId>web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>web</name>
    <description>Web layer of application</description>
    <properties>
        <java.version>11</java.version>
    </properties>

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>

谁能告诉我我做错了什么?或者也许有解决方案可以轻松创建此结构:

文件夹: 网络 主要的 测试 贮存 主要的 测试 它让网络和存储相互交互,比如我什么时候应该在 IntelliJ 中正常运行它们而不是通过 Maven 插件

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)