-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
}