24 lines
1.0 KiB
Java
24 lines
1.0 KiB
Java
package com.ycjy;
|
|
|
|
import com.ycjy.confing.WebConfig;
|
|
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;
|
|
|
|
public class MyInit implements WebApplicationInitializer {
|
|
@Override
|
|
public void onStartup(ServletContext servletContext) throws ServletException {
|
|
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
|
|
rootContext.register(WebConfig.class);
|
|
rootContext.setServletContext(servletContext);
|
|
rootContext.refresh();
|
|
|
|
DispatcherServlet dispatcherServlet = new DispatcherServlet(rootContext);
|
|
ServletRegistration.Dynamic dispatcherServlet1 = servletContext.addServlet("dispatcherServlet", dispatcherServlet);
|
|
dispatcherServlet1.addMapping("/");
|
|
}
|
|
}
|