12345678910111213141516171819202122232425262728293031 |
- package com.lovecoding.mvc;
- import org.springframework.web.WebApplicationInitializer;
- import org.springframework.web.context.support.XmlWebApplicationContext;
- import org.springframework.web.servlet.DispatcherServlet;
- import javax.servlet.ServletContext;
- import javax.servlet.ServletException;
- import javax.servlet.ServletRegistration;
- public class Application implements WebApplicationInitializer {
- @Override
- public void onStartup(ServletContext servletContext) throws ServletException {
- System.out.println( "我被调用了!!!" );
- XmlWebApplicationContext applicationContext = new XmlWebApplicationContext();
- applicationContext.setConfigLocation("classpath:spring.xml");
- DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);
- ServletRegistration.Dynamic dispatcher =
- servletContext.addServlet("dispatcher", dispatcherServlet);
- dispatcher.setLoadOnStartup(1);
- dispatcher.addMapping("/");
- }
- }
|