Configuring custom static path mappings
In the previous recipe, we looked at how to tune the URL path mapping for requests and translate them into controller methods. It is also possible to control how our web application deals with static assets and the files that exist on the filesystem or are bundled in the deployable archive.
Let's say that we want to expose our internal application.properties
file via the static web URL of http://localhost:8080/internal/application.properties
from our application. To get started with this, proceed with the steps in the next section.
How to do it...
- Let's add a new method,
addResourceHandlers
, to theWebConfiguration
class with the following content:
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/internal/**") .addResourceLocations("classpath:/"); }
- Start the application by running
./gradlew clean bootRun
- Let's open
http://localhost:8080/internal/application.properties
in the browser...