How to use two url mappings

I want to port my application to Spring Boot jar deployment. It is currently using Spring 4 no boot.

I have a REST API listener in /api/*

and a Javascript Frontend in src/main/webapp

that can be accessed in /*

.

Now I haven't found a way to do the same in Boot.

I was able to listen to the api in /api/*

by changing the property server.context-path

, but I was unable to register a second servlet to serve my js interface in /*

. I know that src/main/webapp

jar deployment is not supported and I also know that Spring Boot serves static files with src/resources/public

and src/resources/static

. But in my case this folder also points to /api/*

because of the change server.context-path

.

I tried to register another servlet as a bean. This destroyed my API endpoint.

What would be the best way to achieve this?

+3


source to share


1 answer


The first option is to copy everything from src/main/webapp

to src/resources/static

. This is where Spring Boot looks for this static content.

Second option, use src/main/webapp

, but configure your assembly to copy static resources to target/classes/static

. I provided a Maven config for this in a previous answer: Updating Static Content with Spring MVC and Boot



Note that if you go to the first option, if you want to change the content and reload it without starting the build, you will need to run the application in your IDE. Going with the second option gives you a normal Tomcat static content reload if you are running your jar, but it can lead to some confusion. Personally, I use the second option most of the time, as I like to run the application on the command line and edit my HTML and JavaScript using the Chrome Dev tools.

0


source







All Articles