Spring3.1.1学习笔记03-aurora-web-test
5、因为是web项目,我们之前又删除了web.xml文件。所以,第一步是建立一个web的入口类。入口类如下:
src/main/java-org.aurora.config-ApplicationInitialize.java
?
package org.aurora.config;import javax.servlet.ServletContext;import javax.servlet.ServletException;import org.springframework.web.WebApplicationInitializer;import org.springframework.web.context.ContextLoaderListener;import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;public class ApplicationInitialize implements WebApplicationInitializer {public void onStartup(ServletContext servletContext) throws ServletException {AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();servletContext.addListener(new ContextLoaderListener(rootContext));}}
个人从代码的文字上理解,这个onStartup实际上就是web程序的入口,就是一个空的web.xml文件
6、现在启动jetty,看看效果。Run as-Run configurations-maven-new app-jetty:run,启动应该正常了,打开浏览器输入http://localhost:8080/index.jsp