문제

다른 전쟁에 따라 전쟁이있는 Maven Multi Module로 작업하고 있습니다.

Spring Boot WebApp는 HTML 파일 만 제공하는 기본 WebApp에 따라 다릅니다.

Spring Boot App을 실행하면 주 WebApp (Spring Boot One)에서 서비스 및 HTML에 액세스 할 수 있지만 Dependency WAR (404)에서 HTML 파일에 액세스 할 수 없습니다. 그러나 이러한 HTML 파일은 Spring Boot WebApp War 전쟁에 잘 포장되어 있습니다 ...

여기 문제를 보여주는 프로젝트입니다. https://github.com/cthiebault/spring-boot-waroverlays

이 프로젝트에는 2 개의 전쟁 모듈이 있습니다.

  • 종속성 - Webapp : 기본 웹 앱은 HTML (/dependency/index.html)
  • 팀을 제공합니다.
  • main-webapp : Spring Boot WebApp (스프링 가이드에서 복사 됨 GS-Serving-Web-content ). 이 WebApp에는 dependency-webapp 에 대한 종속성이 있습니다.

여기에 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>
.

WebApp 실행 :

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
.

무엇이 잘못되었는지에 대한 어떤 생각입니까?

도움이 되었습니까?

해결책

스프링 부트 플러그인은 오버레이 (꽤 기본)에 대해 알지 못하기 때문에 GitHub에서 원하는 경우 문제를 제기 할 수 있습니다.프로젝트의 WAR 파일은 (java -jar와 함께) 괜찮습니다. 그래서 다른 모든 것이 작동합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top