为什么maven模块不能识别java和spring?

i2loujxw  于 2021-07-23  发布在  Java
关注(0)|答案(0)|浏览(193)

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

正如您在下面看到的,java包不再是java的:

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

当我添加这些模块时,它们的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>

有人能告诉我我做错了什么吗?或者有一种解决方案可以轻松创建这种结构:
父文件夹:web主测试存储主测试,它让web和存储相互作用,就像我应该在intellij中正常运行它们,而不是通过maven插件?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题