【问题标题】:Can't get access to webapp resources of child module of maven/spring boot无法访问maven/spring boot子模块的webapp资源
【发布时间】:2017-11-29 21:30:15
【问题描述】:

我有很好的 spring-boot 应用程序,其结构如下:

现在我尝试使用父 (pom) 和两个子 (jar) 和 (war) 实现多模块架构。看起来像:

但现在我在 loclahost:8080 上有 404。 看起来我无法访问子模块静态资源。

父 pom:

...
<modules>
    <module>liquibase</module>
    <module>server</module>
</modules>

...

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

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

<packaging>pom</packaging>

还有孩子 pom:

<parent>
    <artifactId>stable-backend</artifactId>
     <groupId>...</groupId>
     <version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>server</artifactId>

<packaging>war</packaging>

这有什么问题?

更新 我把我的 html 放到 server/src/webapp/ 在第一种情况下,它就像一个魅力。 关于访问,我的意思是从浏览器获取html。

更新 2 当我运行 spring-boot:run maven 任务时,它也可以正常工作。 只有当我在 intellij“运行”按钮上作为 spring 项目运行时才会出现问题。

【问题讨论】:

  • 静态资源在哪里?以及您是如何尝试访问它的?
  • 你找到了正确的方法让它为你工作吗?

标签: java spring maven spring-boot multi-module


【解决方案1】:

尝试将maven插件改成

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <classifier>exec</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>

让重新打包进程依赖的模块

【讨论】:

  • 不幸的是,没有帮助。
【解决方案2】:

我回答这个问题可能有点晚了,但你仍然可以让它在 Intellij 中工作。

您只需要执行以下操作:

  1. 转到运行>编辑配置

  2. 将您的工作目录设置为子模块的根目录。在您的示例中,我认为应该是:[project_directory]/stable-backend/server

注意:默认情况下,IntelliJ 将您的工作目录设置为顶级模块,在您的情况下,它可能是:[project_directory]/stable-backend/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2022-01-11
    • 2021-12-26
    • 2018-12-26
    相关资源
    最近更新 更多