Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot & Maven war overlay

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

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

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...

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

This project has 2 war modules:

  • 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.

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>

Run the webapp:

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

EDIT 1: Here are the logs when I try to access html pages:

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 --> ERROR 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

Any idea of what's wrong?

like image 530
Cedric Thiebault Avatar asked Jun 03 '14 21:06

Cedric Thiebault


People also ask

What is an spring boot?

Spring Boot is an open source Java-based framework used to create a micro Service. It is developed by Pivotal Team and is used to build stand-alone and production ready spring applications. This chapter will give you an introduction to Spring Boot and familiarizes you with its basic concepts.

What is the use of spring boot?

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need minimal Spring configuration.

Is spring boot and Java same?

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications. It's a Java-based framework used to create a microservice ( microservice is defined as the small services that work together.

What is spring boot and how it works?

Spring Boot is an open source, microservice-based Java web framework. The Spring Boot framework creates a fully production-ready environment that is completely configurable using its prebuilt code within its codebase.


1 Answers

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.

like image 146
Dave Syer Avatar answered Oct 19 '22 06:10

Dave Syer