MyWebAppInitializer.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package com.sf;
  2. import jakarta.servlet.ServletContext;
  3. import jakarta.servlet.ServletException;
  4. import jakarta.servlet.ServletRegistration;
  5. import org.springframework.web.WebApplicationInitializer;
  6. import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
  7. import org.springframework.web.servlet.DispatcherServlet;
  8. // 代替web.xml
  9. // 需要实现WebApplicationInitializer 是web应用程序的初始化器
  10. //public class MyWebAppInitializer implements WebApplicationInitializer {
  11. //
  12. // // 是启动tomcat后要执行的逻辑
  13. // @Override
  14. // public void onStartup(ServletContext servletContext) throws ServletException {
  15. // // 通过注解 获取容器
  16. // AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
  17. // // 把springmvc的配置 注册进去
  18. // context.register(SpringMvcConfig.class);
  19. // context.setServletContext(servletContext);
  20. //
  21. // // <servlet-name>dispatcherServlet</servlet-name>
  22. // // <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  23. // ServletRegistration.Dynamic dispatcher =
  24. // servletContext.addServlet("dispatcherServlet", new DispatcherServlet(context));
  25. // // <load-on-startup>1</load-on-startup>
  26. // dispatcher.setLoadOnStartup(1);
  27. // // <servlet-mapping>
  28. // // <servlet-name>dispatcherServlet</servlet-name>
  29. // // <url-pattern>/</url-pattern>
  30. // // </servlet-mapping>
  31. // dispatcher.addMapping("/");
  32. // }
  33. //}