更新时间:2022-01-26 23:56:48
您只需要启用默认的 servlet,这可以通过将以下内容添加到您的 MvcConfiguration
中来完成:
You only need to enable the default servlet, this is done by adding the following to your MvcConfiguration
:
@Configuration
@EnableWebMvc
public class MvcConfiguration extends WebMvcConfigurerAdapter{
@Bean
public ViewResolver getViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/");
resolver.setSuffix(".html");
return resolver;
}
@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
本质上发生的事情是 Spring 不知道如何在本机处理此类内容(可能是 jsp 说的),而这种配置是告诉它委托给容器的方式.
Essentially what is happening is Spring does not know how to handle the handling of such content natively(could be a jsp say), and to this configuration is the way to tell it to delegate it to the container.