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

以你之姓@ 2022-07-12 06:20 185阅读 0赞

使用如下代码时:

public class MyWebApplicationInitializer implements 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 里面设置

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

发表评论

表情:
评论列表 (有 0 条评论,185人围观)

还没有评论,来说两句吧...

相关阅读