傳統的xml配置方式
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:conf/spring-mvc.xml
1
dispatcherServlet
*.action
Spring Boot配置方式
@Configuration
public class MyWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
//開啟路徑字尾比對
configurer.setUseRegisteredSuffixPatternMatch(true);
}
}
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean
public ServletRegistrationBean servletRegistrationBean(DispatcherServlet dispatcherServlet) {
ServletRegistrationBean servletServletRegistrationBean = new ServletRegistrationBean<>(dispatcherServlet);
servletServletRegistrationBean.addUrlMappings("*.action");
return servletServletRegistrationBean;
}
}