package com.sf;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRegistration;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
// 代替web.xml
// 需要实现WebApplicationInitializer 是web应用程序的初始化器
//public class MyWebAppInitializer implements WebApplicationInitializer {
//
// // 是启动tomcat后要执行的逻辑
// @Override
// public void onStartup(ServletContext servletContext) throws ServletException {
// // 通过注解 获取容器
// AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
// // 把springmvc的配置 注册进去
// context.register(SpringMvcConfig.class);
// context.setServletContext(servletContext);
//
// // dispatcherServlet
// // org.springframework.web.servlet.DispatcherServlet
// ServletRegistration.Dynamic dispatcher =
// servletContext.addServlet("dispatcherServlet", new DispatcherServlet(context));
// // 1
// dispatcher.setLoadOnStartup(1);
// //
// // dispatcherServlet
// // /
// //
// dispatcher.addMapping("/");
// }
//}