spring-boot 启动的同时执行代码

只需要写一个类继承CommandLineRunner然后实现run方法,run方法即会在此项目启动时执行

package com.jerry.work.runner;

import com.jerry.work.reminder.Reminder;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 
 */
@Component
@Order(value=1)
public class StartupRunner implements CommandLineRunner
{
    @Override
    public void run(String... args) throws Exception
    {
        System.out.println("启动springboot");
    }
}

你可能感兴趣的:(spring-boot 启动的同时执行代码)