1. Using a custom resource path
In your web configuration
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { if (!registry.hasMappingForPattern("/assets/**")) { registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/assets/"); } }
Put your style.css file inside this folder
src/main/resources/assets/css/
After that in your submissions
<link rel="stylesheet" type="text/css" th:href="@{/assets/css/style.css}" />
.
2. Using predefined paths in spring boot
Remove addResourceHandlers from your web config
Put style.css in any of the following folders
src/main/resources/META-INF/resources/assets/csssrc/main/resources/resources/assets/css/src/main/resources/static/assets/css/src/main/resources/public/assets/css/
And in the view
<link rel="stylesheet" type="text/css" th:href="@{/assets/css/style.css}" />
.
NOTE. Here you can delete the assets folder. If you want to do this, delete it from the predefined resource folder, as well as from the th:href view. But I saved it like this because you explicitly mentioned the assets/ path in your question. Therefore, I believe in your requirement to have assets/ in the URL of your resource.
source share