我们可以在服务器启动java之后打印hello world而不使用任何servlet和jsp
我已经尝试通过在web .xml中编写Listener来使用Spring。
listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
写一堂课
public class ContextFactory implements ApplicationContextAware {
private static ApplicationContext context ;
static{
System.out.println("*****HELLO WORLD!*******");
}
public void setApplicationContext(ApplicationContext context)
throws BeansException {
ContextFactory.context = context;
}
public static ApplicationContext getContext() {
return context;
} }
但是它是在服务器启动之前打印的
Jan 24, 2013 5:03:01 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8588"]
Jan 24, 2013 5:03:01 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8509"]
Jan 24, 2013 5:03:01 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 618 ms
Jan 24, 2013 5:03:01 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 24, 2013 5:03:01 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.16
Jan 24, 2013 5:03:01 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive MatchStandardizationEngine.war
Jan 24, 2013 5:03:01 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/softwares/apache-tomcat-7.0.16/webapps/MatchStandardizationEngine/WEB-INF/lib/javaee-api-5.1.0-M1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
********HELLO WORLD!***********
Jan 24, 2013 5:03:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Jan 24, 2013 5:03:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Jan 24, 2013 5:03:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Jan 24, 2013 5:03:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory host-manager
Jan 24, 2013 5:03:03 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory manager
Jan 24, 2013 5:03:03 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8588"]
Jan 24, 2013 5:03:03 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8509"]
Jan 24, 2013 5:03:03 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2539 ms