请问,如何在tomcat启动时,将自己的自定义信息打印到控制台?
 信息: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
六月 21, 2017 11:12:13 上午 org.apache.catalina.startup.TaglibUriRule body
信息: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
六月 21, 2017 11:12:13 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
六月 21, 2017 11:12:13 上午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath

======================================================================

    欢迎使用 JeeSite 快速开发平台  - Powered By http://jeesite.com

======================================================================

六月 21, 2017 11:12:14 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
六月 21, 2017 11:12:27 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring FrameworkServlet 'springServlet'
========= Enabled refresh mybatis mapper =========
六月 21, 2017 11:12:38 上午 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory C:\tomcat\apache-tomcat-7.0.75\webapps\docs
六月 21, 2017 11:12:38 上午 org.apache.catalina.startup.TldConfig execute
信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for th

4个回答

写一个类,实现startupListener接口,在init方法里面打印日志

首先,可以自定义一个HttpServlet,然后添加到web.xml中设置为容器启动时加载,一般就可以在自己定义的Servlet类中添加一些系统初始化的工作了。
类似SpringMVC启动时的监听器的配置一样:

 <load-on-startup>1</load-on-startup>

自己写一个listener
public class MyListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {

    System.out.println(" ......................我佛慈悲......................");
    System.out.println("                       _oo0oo_                      ");
    System.out.println("                      o8888888o                     ");
    System.out.println("                      88\" . \"88                     ");
    System.out.println("                      (| -_- |)                     ");
    System.out.println("                      0\\  =  /0                     ");
    System.out.println("                    ___/‘---’\\___                   ");
    System.out.println("                  .' \\|       |/ '.                 ");
    System.out.println("                 / \\\\|||  :  |||// \\                ");
    System.out.println("                / _||||| -卍-|||||_ \\               ");
    System.out.println("               |   | \\\\\\  -  /// |   |              ");
    System.out.println("               | \\_|  ''\\---/''  |_/ |              ");
    System.out.println("               \\  .-\\__  '-'  ___/-. /              ");
    System.out.println("             ___'. .'  /--.--\\  '. .'___            ");
    System.out.println("          .\"\" ‘<  ‘.___\\_<|>_/___.’ >’ \"\".          ");
    System.out.println("         | | :  ‘- \\‘.;‘\\ _ /’;.’/ - ’ : | |        ");
    System.out.println("         \\  \\ ‘_.   \\_ __\\ /__ _/   .-’ /  /        ");
    System.out.println("     =====‘-.____‘.___ \\_____/___.-’___.-’=====     ");
    System.out.println("                       ‘=---=’                      ");
    System.out.println("                                                    ");
    System.out.println("....................佛祖开光 ,永无BUG...................");
}

@Override
public void contextDestroyed(ServletContextEvent sce) {

}

}

在web.xml中配置

com.listener.MyListener

自己写一个listener


public class MyListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {

    System.out.println(" ......................我佛慈悲......................");
    System.out.println("                       _oo0oo_                      ");
    System.out.println("                      o8888888o                     ");
    System.out.println("                      88\" . \"88                     ");
    System.out.println("                      (| -_- |)                     ");
    System.out.println("                      0\\  =  /0                     ");
    System.out.println("                    ___/‘---’\\___                   ");
    System.out.println("                  .' \\|       |/ '.                 ");
    System.out.println("                 / \\\\|||  :  |||// \\                ");
    System.out.println("                / _||||| -卍-|||||_ \\               ");
    System.out.println("               |   | \\\\\\  -  /// |   |              ");
    System.out.println("               | \\_|  ''\\---/''  |_/ |              ");
    System.out.println("               \\  .-\\__  '-'  ___/-. /              ");
    System.out.println("             ___'. .'  /--.--\\  '. .'___            ");
    System.out.println("          .\"\" ‘<  ‘.___\\_<|>_/___.’ >’ \"\".          ");
    System.out.println("         | | :  ‘- \\‘.;‘\\ _ /’;.’/ - ’ : | |        ");
    System.out.println("         \\  \\ ‘_.   \\_ __\\ /__ _/   .-’ /  /        ");
    System.out.println("     =====‘-.____‘.___ \\_____/___.-’___.-’=====     ");
    System.out.println("                       ‘=---=’                      ");
    System.out.println("                                                    ");
    System.out.println("....................佛祖开光 ,永无BUG...................");
}

@Override
public void contextDestroyed(ServletContextEvent sce) {

}

}


在web.xml中配置

    <listener>
        <listener-class>com.atguigu.listener.MyListener</listener-class>
    </listener>


Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问