Created
December 4, 2014 11:17
-
-
Save songyunlu/2a0cbf27e522dd4a8f70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package demo; | |
import java.util.Arrays; | |
import javax.servlet.ServletContext; | |
import javax.servlet.ServletException; | |
import org.apache.catalina.LifecycleListener; | |
import org.apache.commons.logging.Log; | |
import org.apache.commons.logging.LogFactory; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; | |
import org.springframework.boot.context.embedded.ServletContextInitializer; | |
import org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener; | |
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
@ComponentScan | |
@EnableAutoConfiguration | |
public class Application { | |
public static void main(String[] args) { | |
SpringApplication.run(Application.class, args); | |
} | |
@Bean | |
public EmbeddedServletContainerFactory servletContainer() { | |
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); | |
ServletContextInitializer ctxtInitializer = new MyServletContextInitializer(); | |
LifecycleListener listener = new ServletContextInitializerLifecycleListener(ctxtInitializer); | |
tomcat.setContextLifecycleListeners(Arrays.asList(listener)); | |
return tomcat; | |
} | |
} | |
class MyServletContextInitializer implements ServletContextInitializer { | |
private static final Log log = LogFactory.getLog(MyServletContextInitializer.class); | |
@Override | |
public void onStartup(ServletContext servletContext) throws ServletException { | |
log.info("the tomcat starts up"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment