Skip to content
Advertisement

Why does root path in my controller maps to index.html in spring boot web application?

I’m testing a controller for a Spring Boot application. I want to map a resource to a path, which should be a part of my API. My controller is pretty specific about path:

JavaScript

Here ‘web-interface’ is a property, as specified in application.yml file

JavaScript

Expected behavior:

path: localhost:8080/admin maps to index.html resource

root path: localhost:8080/ maps to nothing, i.e. 404 error.

Actual behavior:

path: ‘/admin’ maps to index.html

path: ‘/’ also maps to index.html

But why? Shouldn’t I just see “Whitelabel Error Page”. There is no controller, which maps root path to index.html file. It doesn’t make any sense.

By the way, here is my project structure.

enter image description here

Solution:

Rename index.html to any other name, like main.html and root path ‘/’ will no longer map to that resource.

Advertisement

Answer

Root path “/” by defaults maps to index.html. It is standard for all languages and frameworks. index.html is meant to be entry point for your application

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement