如何在spring-boot中自定义dispatchServlet的访问路径
如何在spring-boot中自定义dispatchServlet的访问路径?
在程序的主入口中定义dispatchRegistration
package com.lzl
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.web.servlet.ServletComponentScan
import org.springframework.boot.web.servlet.ServletRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.web.servlet.DispatcherServlet
import com.lzl.servlet.MyServlet
@SpringBootApplication
public class SpringBootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootDemoApplication.class, args)
}
@Bean
public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {
ServletRegistrationBean reg = new ServletRegistrationBean(dispatcherServlet)
reg.getUrlMappings().clear()
reg.addUrlMappings("*.html")
reg.addUrlMappings("*.do")
return reg
}
}