あなたが望むものを達成する最も簡単な方法は、カスタム404ハンドラを実装することです。
はこれらのparamsをごapplication.propertiesに追加:
spring.resources.add-mappings=false
spring.mvc.throw-exception-if-no-handler-found=true
最初のプロパティは、すべてデフォルトの静的リソースの取り扱いを削除し、第二の特性は、(デフォルトの春でNoHandlerFoundException
をキャッチし、標準のホワイトレーベルのページを用意しています)Springのデフォルトのホワイトレーベルのページを無効にします
アプリケーションコンテキストに404ハンドラを追加します。
あなたは(このケースではindex.html)あなたの静的なコンテンツを提供するためにカスタムビューリゾルバを追加する必要があります終わり
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.UrlBasedViewResolver;
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/index.html").addResourceLocations("classpath:/static/index.html");
super.addResourceHandlers(registry);
}
@Bean
public ViewResolver viewResolver() {
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
viewResolver.setViewClass(InternalResourceView.class);
return viewResolver;
}
}
あなたindex.html
/resources/static/
ディレクトリに配置する必要があります。