Reputation: 6574
I am building web application using spring boot for backend and angular2 for frontend, spring boot return whitelabel page if a none root url was accessed (because the servlet container does not know about the angular routing), so I am trying to replace the whitelabel page with the index.html page.
After reading some article about this i tried this but not working
@Component
public class CustomizationBean
implements EmbeddedServletContainerCustomizer {
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/index.html"));
}
}
index.html is placed under src/main/resources/static
Am I missing something?
Upvotes: 0
Views: 1044
Reputation: 22442
The above code works perfectly fine to display index.html
page (instead of white label error), but you need to ensure that your CustomizationBean
is available for scanning for the Spring container during the start up @ComponentScan(basePackages = { "com.yourproject"})
As far as I know, in spring boot the scan is automatic , I have my CustomizationBean annotation with @Component.
Spring boot, by default only scans the classes under the myproject
packages (where ApplicationLauncher
main
class resides) as explained in this doc here. The rest of the packages need to be specified in @ComponentScan
Upvotes: 1