添加logback-spring.xml,将log输出到文件,控制台输出的level改为error因此只会出处banner

src/main/resources/banner.txt的内容为

start...

但是输出完banner后,spring boot并没有启动完毕

因此,我想在Spring boot启动成功后输出提示

有两种方式

1.实现 ApplicationRunnerImpl

eg:

package com.example.demo.configure;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component; @Component
public class ApplicationRunnerImpl implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("application start...");
}
}

2.实现 CommandLineRunnerImpl

eg:

package com.example.demo.configure;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component; @Component
public class CommandLineRunnerImpl implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("application start...");
}
}

输出:  

start...
application running...

注:

  执行时机为容器启动完成的时候

  run方法中接收的参数类型不一样

  如果有多个实现类,并且需要按一定顺序执行,可以在实现类上加上@Order注解。@Order(value=整数值)。SpringBoot会按照@Order中的value值从小到大依次执行

Spring boot启动成功后输出提示的更多相关文章

  1. spring boot 启动类一定要放置到包的根目录下,也就是和所有包含java文件的包在同一级目录。如果不放置在根目录下,将会提示 no mybatis mapper was found

    spring boot 启动类一定要放置到包的根目录下,也就是和所有包含java文件的包在同一级目录.将会将同一目录下的包扫描成bean. 如果不放置在根目录下,将会提示 no mybatis map ...

  2. Spring Boot 启动原理分析

    https://yq.aliyun.com/articles/6056 转 在spring boot里,很吸引人的一个特性是可以直接把应用打包成为一个jar/war,然后这个jar/war是可以直接启 ...

  3. Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动

    之前在Spring Boot启动过程(二)提到过createEmbeddedServletContainer创建了内嵌的Servlet容器,我用的是默认的Tomcat. private void cr ...

  4. Spring Boot启动过程(七):Connector初始化

    Connector实例的创建已经在Spring Boot启动过程(四):Spring Boot内嵌Tomcat启动中提到了: Connector是LifecycleMBeanBase的子类,先是设置L ...

  5. Spring Boot 启动(一) SpringApplication 分析

    Spring Boot 启动(一) SpringApplication 分析 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html ...

  6. springboot项目启动成功后执行一段代码的两种方式

    springboot项目启动成功后执行一段代码的两种方式 实现ApplicationRunner接口 package com.lnjecit.lifecycle; import org.springf ...

  7. spring boot启动原理步骤分析

    spring boot最重要的三个文件:1.启动类 2.pom.xml 3.application.yml配置文件 一.启动类->main方法 spring boot启动原理步骤分析 1.spr ...

  8. Spring Boot 启动事件和监听器,太强大了!

    大家都知道,在 Spring 框架中事件和监听无处不在,打通了 Spring 框架的任督二脉,事件和监听也是 Spring 框架必学的核心知识之一. 一般来说,我们很少会使用到应用程序事件,但我们也不 ...

  9. Spring Boot -- 启动彩蛋

    使用Spring Boot启动的jar包总是会显示一个Spring的图标: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\_ ...

随机推荐

  1. vector rIterator

    #include<vector> #include<iostream> using namespace std; void main() { vector<int> ...

  2. Excel——读取——导出目录

    /** * 导出Excel文件到具体的目录 * <一句话功能简述> * <功能详细描述> * @param fileName 导出的文件名 * @param sheetName ...

  3. How would you differentiate JDK, JRE, JVM, and JIT?

    Q5. How would you differentiate JDK, JRE, JVM, and JIT?A5. There is no better way to get the big pic ...

  4. objc_object 与 NSObject

    objc_object 与 NSObject:同一个事物的不同表现形式.

  5. hdu2068-RPG的错排-(dp递推式)

    去年看错排公式,死都看不懂,基础扎实之后再来看就略懂了. 公式: dp[ n ] = ( n-1 ) * ( dp[n-1] + dp[n-2] ) 解析公式:比如有n个元素,各对应n个正确位置,dp ...

  6. hive基础知识一

    1. Hive是什么 1.1 hive的概念 Hive:由Facebook开源,用于解决海量(结构化日志)的数据统计. Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张表 ...

  7. bat 添加环境变量

    修改环境变量 :输入 “set 变量名=变量内容”即可,比如将path设置为“d:\hacker.exe”,只要输入set path="d:\nmake.exe".注意,此修改环境 ...

  8. 使用 Python 和 Flask 设计 RESTful API

    近些年来 REST (REpresentational State Transfer) 已经变成了 web services 和 web APIs 的标配. 在本文中我将向你展示如何简单地使用 Pyt ...

  9. 如何设置select只读不可编辑且select的值可传递(摘自百度)

    selectname="role"id="role"οnfοcus="this.defaultIndex=this.selectedIndex;&qu ...

  10. Zabbix实战-简易教程--中间件RabbitMQ监控

    一.环境 zabbix版本:3.0 二.脚本说明 .├── rabbitmq.template.xml   模板文件├── scripts  │   └── rabbitmq│   ├── api.p ...