Application.java 1019 B

12345678910111213141516171819202122232425262728293031
  1. package com.lovecoding.mvc;
  2. import org.springframework.web.WebApplicationInitializer;
  3. import org.springframework.web.context.support.XmlWebApplicationContext;
  4. import org.springframework.web.servlet.DispatcherServlet;
  5. import javax.servlet.ServletContext;
  6. import javax.servlet.ServletException;
  7. import javax.servlet.ServletRegistration;
  8. public class Application implements WebApplicationInitializer {
  9. @Override
  10. public void onStartup(ServletContext servletContext) throws ServletException {
  11. System.out.println( "我被调用了!!!" );
  12. XmlWebApplicationContext applicationContext = new XmlWebApplicationContext();
  13. applicationContext.setConfigLocation("classpath:spring.xml");
  14. DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);
  15. ServletRegistration.Dynamic dispatcher =
  16. servletContext.addServlet("dispatcher", dispatcherServlet);
  17. dispatcher.setLoadOnStartup(1);
  18. dispatcher.addMapping("/");
  19. }
  20. }