2014-09-28 61 views

回答

1

不知道你通过注释的“重新映射的Spring MVC的DispatcherServlet”的意思,但如果你的意思是创建在JavaDispatcherServlet不使用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 
}