2014-09-28 63 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 
}