Spring MVC looks for a file named [servlet-name]-servlet.xml in the WEB-INF

来源:互联网 发布:下载压缩包软件 编辑:程序博客网 时间:2024/05/29 00:34

使用如下代码时:

public class MyWebApplicationInitializerimplements WebApplicationInitializer {

  @Override public void onStartup(ServletContext container) {

ServletRegistration.Dynamic registration = container.addServlet("example"new DispatcherServlet());

 registration.setLoadOnStartup(1);

 registration.addMapping("/example/*");

}

}

会发生如下错误

Spring MVC looks for a file named example-servlet.xml in the WEB-INF 


实现基于java的零xml配置,需要在DispatcherServlet 里面设置

WebApplicationContext
具体方法如下
AnnotationConfigWebApplicationContext servletAppContext = new AnnotationConfigWebApplicationContext();Class<?>[] configClasses = new Class[]{WebConfig.class};if (!ObjectUtils.isEmpty(configClasses)) {    servletAppContext.register(configClasses);}
new DispatcherServlet(servletAppContext);


0 0
原创粉丝点击