0
votes

I have a Spring Boot 2.0 application that I'm trying to deploy as a WAR file. This means that it will have a custom context path. To test as a Java application I added

server.servlet.context-path=/MyApplication

to the application.properties. In my index.html (located in src/main/resources/static) I try to include Javascript using something like this:

<script src="dist/main.js"</script>

Regardless of whether I am using the context path, this always tries to load the file from http://localhost:8080/dist/main.js completely ignoring the context path I have specified. The same is true if I try to deploy my application as a WAR. The file is really at http://localhost:8080/MyApplication/dist/main.js.

What do I need to change in my configuration to make Spring Boot use the context path when serving static content?

2

2 Answers

2
votes

I just figured it out. In my index.html I had set a base href:

<base href="/">

I converted index.html to a JSP and set the base href using a JSP tag:

<base href='<c:url value="/" />'>
1
votes

Modify the <base href="/"> in index.html to the following,

<base href="./">

This will try to load all the scripts from the context path that is specified and it fixed the issue for me.