質問

私は、他の戦争に依存する戦争を伴う Maven マルチモジュールを使用しています。

Spring Boot Web アプリは、HTML ファイルのみを提供する基本的な Web アプリに依存しています。

Spring Boot アプリを実行すると、メイン Web アプリ (Spring Boot アプリ) からサービスと HTML にアクセスできますが、依存関係戦争 (404) から HTML ファイルにアクセスできません。しかし、これらの HTML ファイルは Spring Boot Web アプリ戦争でうまくパッケージ化されています...

この問題を示すプロジェクトは次のとおりです。
https://github.com/cthiebault/spring-boot-war-overlays

このプロジェクトには 2 つの戦争モジュールがあります。

  • 依存関係-ウェブアプリ:HTML のみを提供する基本的な Web アプリ (/dependency/index.html)
  • メインウェブアプリ:Spring Boot Web アプリ (Spring ガイドからコピー) gs-serving-web-content)。この Web アプリには依存関係があります 依存関係-ウェブアプリ.

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>

Web アプリを実行します。

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

編集1:HTML ページにアクセスしようとしたときのログは次のとおりです。

http://localhost:8080/index.html --> OK

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 を使用して) 正常にデプロイおよび実行されるため、他のすべては機能しています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top