11-ApplicationRunner或CommandLineRunner run完成之后启动

261 阅读1分钟

如果需要在SpringApplication启动后运行某些特定代码,可以实现ApplicationRunner或CommandLineRunner接口。

package com.jeegit.starter;


import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Component
public class JeeGgitApplicationRunner implements ApplicationRunner {

    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("JeeGgitApplicationRunner--欢迎来到JeeGit V1.0.1 企业级信息化快速开发平台");
    }
}

另外的代码

package com.jeegit.starter;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class JeeGitCommandLineRunner implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {


            System.out.println("JeeGitCommandLineRunner--欢迎来到JeeGit V1.0.1 企业级信息化快速开发平台");

    }
}