spring boot运行时不从父/聚合器模块加载静态资源

时间:2016-09-18 18:47:24

标签: java maven tomcat spring-boot spring-boot-maven-plugin

我一直在努力解决以下问题大约一个星期,我找不到任何有同样问题的人。

我有一个Maven项目,它由几个子模块构成,如下所示:

parent-module
   child A (common library)
   child B (spring boot application - no static content)
   child C (spring boot application - static content and JSP

在B和C的集成测试中,我使用的是spring-boot-maven-plugin,它在集成测试之前运行WAR,并在集成测试之后停止。

导航到任何子模块并执行“mvn verify”没有问题。但是,如果我在父模块中执行“mvn verify”,则子A和B将通过,但子C将失败,因为无法找到静态内容和JSP页面。

我认为问题是由于Maven将从父模块而不是从子模块运行应用程序,因此tomcat无法找到资源和WEB-INF文件夹。

例如,在父项目中执行以下命令:

parent> mvn -pl ../childC spring-boot:run

将启动子C,但应用程序将找不到静态资源。但是,来自子C模块的以下命令将正常工作:

childC> mvn spring-boot:run

另外,为了检查我在自己的项目依赖项中没有做过任何可疑的事情,我下载了spring boot tomcat jsp example并创建了这样的父POM:

<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>
    <version>0.0.1-SNAPSHOT</version>
    <artifactId>my-parent</artifactId>
    <packaging>pom</packaging>
    <name>my-parent</name>
    <groupId>com.test</groupId>
    <modules>
        <module>../jspsample</module>
    </modules>
</project>

我刚刚修改了弹簧启动示例pom的父级,如下所示:

...
<parent>
    <groupId>com.test</groupId>
    <artifactId>my-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../myparent</relativePath>
</parent>
...

现在,如果我从父模块执行以下操作

myparent> mvn -pl ../jspsample spring-boot:run

在我们的浏览器中打开http://localhost:8080

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Sun Sep 18 20:38:23 CEST 2016
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/jsp/welcome.jsp

所以,似乎spring-boot:run不能从父模块运行。有没有人有解决此问题的方法。是否可以在启动WAR / JAR之前指示Maven或spring引导插件导航到子模块?

需要注意的是,我最近将我的“标准”弹簧MVC项目移植到弹簧启动。在春季启动之前,我使用了tomcat maven插件而不是spring boot插件,而且这个插件工作正常。

0 个答案:

没有答案