Spring boot啓動成功後輸出提示

添加logback-spring.xml,將log輸出到文件,控制檯輸出的level改成error所以只會出處bannerspring

src/main/resources/banner.txt的內容爲 app

start...

可是輸出完banner後,spring boot並無啓動完畢ide

所以,我想在Spring boot啓動成功後輸出提示spa

有兩種方式code

1.實現 ApplicationRunnerImplxml

eg:blog

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.實現 CommandLineRunnerImplio

eg:class

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...");
    }
}

輸出:  import

start...
application running...

注:

  執行時機爲容器啓動完成的時候

  run方法中接收的參數類型不同

  若是有多個實現類,而且須要按必定順序執行,能夠在實現類上加上@Order註解。@Order(value=整數值)。SpringBoot會按照@Order中的value值從小到大依次執行

相關文章
相關標籤/搜索