1234567891011121314151617181920212223242526272829303132333435 |
- 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);
- //
- // // <servlet-name>dispatcherServlet</servlet-name>
- // // <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- // ServletRegistration.Dynamic dispatcher =
- // servletContext.addServlet("dispatcherServlet", new DispatcherServlet(context));
- // // <load-on-startup>1</load-on-startup>
- // dispatcher.setLoadOnStartup(1);
- // // <servlet-mapping>
- // // <servlet-name>dispatcherServlet</servlet-name>
- // // <url-pattern>/</url-pattern>
- // // </servlet-mapping>
- // dispatcher.addMapping("/");
- // }
- //}
|