Spring Boot throws 404 when serving static HTML from custom static location -


i new spring boot , have read on docs several articles, , having difficult time serving single static html page. think complicating things here have 2 requirements can't bend on, , don't think docs or these articles address requirements:

  1. i want use yaml external config (so application.yml); and
  2. i want external config external! is, don't want packaged inside uberjar, rather, want deployed along uberjar, decoupled artifact. allows me run same uberjar on environment config file has been deployed.

so start with, have added usual starter poms on compile classpath (mentioning clear snake yaml should on classpath):

compile(     'org.codehaus.groovy:groovy-all:2.4.6'     ,'org.springframework.boot:spring-boot-starter-jetty'     ,'org.springframework.boot:spring-boot-starter-actuator' ) compile('org.springframework.boot:spring-boot-starter-web') {     exclude module: 'spring-boot-starter-tomcat' } 

next, add src/main/resources/webapps/test.html source code:

<html>     <head>         <title>test</title>     </head>     <body>         simple test!     </body> </html> 

next, added application.yml root of project:

spring:   resources:     static-locations:       - 'classpath:/webapps/' 

the idea spring boot find file in root dir when running locally, ci server able deploy arbitrary (environment-specific) application.yml alongside uberjar.

then build uberjar:

./gradlew build 

and run uberjar, passing in command-line arg should tell spring where find config file:

java -dspring.config.location=. -jar build/libs/myapp.jar 

i specify "." because gradle running out of project's root directory, application.yml located.

the app starts fine, , when go http://localhost:8080 see content see (i have @restcontroller maps / simple "hello, spring boot" string). but, when go http://localhost:8080/test.html, 404.

any ideas i'm going awry?

the src/main/resources folder automatically added static resource root spring boot auto configuration. means folders within picked automatically - don't need explicitly add webapps folder.

i tried locally placing test.html /main/resources/lestatic/ folder: http://localhost:8080/test.html works no config, , fails 404 when classpath:/lestatic/ specified resource config.

if doesn't work, should check resources folder included resource root build tool. can verify checking target/classes folder presence of custom folder after complete build.

see spring boot manual


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -