package liulixin;
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 KaiYan implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext)
throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
servletContext.addListener(new ContextLoaderListener(ctx));
ctx.setServletContext(servletContext);
System.out.println("tomcat started");
}
}
只要tomcat已启动,上面这个类就会被调用,大家可以看console中的输出。而且,这不需要再web.xml中做任何配置。
源代码:http://pan.baidu.com/share/link?shareid=1333271130&uk=3878681452