现有一项目,两套API,由于使用同一域名,需要采用URI部分增加命名空间来区分,采取修改DispatcherServlet映射路径的方式进行配置。
Spring Boot 编程式配置
@Bean
public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet) {
return new ServletRegistrationBean(dispatcherServlet,"/web/*");
}
传统配置方式
<!--Spring MVC 配置-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/web/*</url-pattern>
</servlet-mapping>