春季靴子Maven战争叠加 [英] Spring Boot & Maven war overlay

查看:108
本文介绍了春季靴子Maven战争叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一个Maven多模块一起使用,这取决于另一场战争.

I'm working with a Maven multi module with a war depending on an other war.

Spring Boot Webapp依赖于仅提供html文件的基本Webapp.

The Spring Boot webapp depends on a basic webapp that only serves html files.

当我运行Spring Boot应用程序时,我能够从主Web应用程序(Spring Boot之一)访问服务和html,但是无法从依赖项战争中访问html文件(404).但是这些html文件在Spring Boot webapp war中打包得很好...

When I run the Spring Boot app, I'm able to access services and html from the main webapp (the Spring Boot one) but I can't access the html files from the dependency war (404). But these html files are well packaged in the Spring Boot webapp war...

这是一个显示问题的项目:
https://github.com/cthiebault/spring-boot-war-overlays

Here is a project that show the problem:
https://github.com/cthiebault/spring-boot-war-overlays

该项目有2个战争模块:

This project has 2 war modules:

  • dependency-webapp :仅提供html(/dependency/index.html)的基本webapp
  • main-webapp :Spring Boot Webapp(摘自Spring Guides
  • dependency-webapp: basic webapp serving just html (/dependency/index.html)
  • main-webapp: Spring Boot webapp (copied from Spring Guides gs-serving-web-content). This webapp has a dependency on dependency-webapp.

这是主Web应用程序pom.xml:

Here is the main-webapp 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>

  <parent>
    <groupId>spring-boot-overlays</groupId>
    <artifactId>parent</artifactId>
    <version>0.1.0-SNAPSHOT</version>
  </parent>

  <artifactId>main-webapp</artifactId>
  <packaging>war</packaging>

  <dependencies>
    <dependency>
      <groupId>spring-boot-overlays</groupId>
      <artifactId>dependency-webapp</artifactId>
      <version>0.1.0-SNAPSHOT</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <overlays>
            <overlay>
              <groupId>spring-boot-overlays</groupId>
              <artifactId>dependency-webapp</artifactId>
            </overlay>
          </overlays>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <properties>
    <start-class>hello.Application</start-class>
  </properties>

</project>

运行网络应用程序:

mvn install
cd main-webapp
mvn spring-boot:run

当我尝试访问html页面时,以下是日志:

http://localhost:8080/index.html ->确定

o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/index.html]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /index.html
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/index.html]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/index.html] are [/**]
o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/index.html] are {}
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/index.html] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@25595861] and 1 interceptor
o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/index.html] is: -1
o.s.w.s.r.ResourceHttpRequestHandler     : Trying relative path [index.html] against base location: ServletContext resource [/]
o.s.w.s.r.ResourceHttpRequestHandler     : Found matching resource: ServletContext resource [/index.html]
o.s.w.s.r.ResourceHttpRequestHandler     : Determined media type 'text/html' for ServletContext resource [/index.html]
o.s.w.s.r.ResourceHttpRequestHandler     : Resource not modified - returning 304
o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
o.s.web.servlet.DispatcherServlet        : Successfully completed request

http://localhost:8080/dependency/index.html ->错误404

o.s.web.servlet.DispatcherServlet        : DispatcherServlet with name 'dispatcherServlet' processing GET request for [/dependency/index.html]
s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /dependency/index.html
s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/dependency/index.html]
o.s.w.s.handler.SimpleUrlHandlerMapping  : Matching patterns for request [/dependency/index.html] are [/**]
o.s.w.s.handler.SimpleUrlHandlerMapping  : URI Template variables for request [/dependency/index.html] are {}
o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapping [/dependency/index.html] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@25595861] and 1 interceptor
o.s.web.servlet.DispatcherServlet        : Last-Modified value for [/dependency/index.html] is: -1
o.s.w.s.r.ResourceHttpRequestHandler     : Trying relative path [dependency/index.html] against base location: ServletContext resource [/]
o.s.w.s.r.ResourceHttpRequestHandler     : Trying relative path [dependency/index.html] against base location: class path resource [META-INF/resources/]
o.s.w.s.r.ResourceHttpRequestHandler     : Trying relative path [dependency/index.html] against base location: class path resource [resources/]
o.s.w.s.r.ResourceHttpRequestHandler     : Trying relative path [dependency/index.html] against base location: class path resource [static/]
o.s.w.s.r.ResourceHttpRequestHandler     : Trying relative path [dependency/index.html] against base location: class path resource [public/]
o.s.w.s.r.ResourceHttpRequestHandler     : No matching resource found - returning 404
o.s.web.servlet.DispatcherServlet        : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
o.s.web.servlet.DispatcherServlet        : Successfully completed request

有什么问题的想法吗?

推荐答案

Spring Boot插件不了解覆盖(这是非常基本的),因此如果您喜欢github,可以提出有关此问题.项目中的WAR文件可以正常部署和运行(使用java -jar),因此其他所有功能都可以正常工作.

The Spring Boot plugin doesn't know about the overlay (it's pretty basic), so you can raise an issue about that if you like in github. The WAR file from your project deploys and runs (with java -jar) just fine though, so everything else is working.

这篇关于春季靴子Maven战争叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆