静的 HTML ページで Spring Boot + MVC をいじっていると、次のことに気付きました。
まず、私が持っているもの:
インデックス コントローラ:
@Controller
public class IndexController {
@RequestMapping("/")
public String index() {
return "index.html";
}
@RequestMapping("/{path:[^\\.]+}/**")
public String forward() {
return "forward:/";
}
}
Html ファイルは次のとおりです。...\src\main\resources\static\index.html
したがって、私のメインアプリケーションクラスが次の場合:
@SpringBootApplication
public class MyApplication extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
すべてが正常に動作し、デフォルトのパス:ページのコンテンツlocalhost:8080\
を取得しますindex.html
しかし、 Application クラスに注釈を付けると@EnableWebMvc
@SpringBootApplication
@EnableWebMvc
public class MyApplication extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
例外が発生します:javax.servlet.ServletException: Could not resolve view with name 'index.html' in servlet with name 'dispatcherServlet'
しかし、この春のドキュメントによると、それは有効な構成です。
多分誰かが私に理由を説明できますか?私は何か間違っていることを理解していますか?