-1
我想知道是否有可能通過註釋重映射Spring MVC dispatcherServlet從「/」到其他路徑?重映射Spring MVC dispatcherServlet通過註釋到其他路徑
我想知道是否有可能通過註釋重映射Spring MVC dispatcherServlet從「/」到其他路徑?重映射Spring MVC dispatcherServlet通過註釋到其他路徑
不知道你通過註釋的「重新映射的Spring MVC的DispatcherServlet」的意思,但如果你的意思是創建在Java
的DispatcherServlet
不使用XML
,你可以,如果你正在使用Spring 3.2+
使用AbstractAnnotationConfigDispatcherServletInitializer
。
應用類註冊並初始化調度的servlet:
public class Application extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[0];
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{ApplicationConfig.class};
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
的配置類:
@Configuration
@EnableWebMvc
@ComponentScan("foo.bar")
public class ApplicationConfig {
//Add beans if needed
}