Spring Boot 中 CommandLineRunner接口

使用方法详见:https://blog.youkuaiyun.com/catoop/article/details/50501710

探索一下该接口的实现,在该Application中的执行顺序:

import org.springframework.stereotype.Controller;

/**
 * @author 
 * @date 2019/5/10 14:17
 */
@Controller
public class RunnerOrderTestController {
    static{
        System.out.println("Controller的静态代码块");
    }
    {
        System.out.println("Controller的动态代码块");
    }
}
import com.example.demo.springCach.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 
 * @date 2019/5/10 14:16
 */
@Configuration
public class RunnerOrderTestConfig {
    @Bean
    public User testOrder(){
        System.out.println("我是Configuration中的Bean");
        return null;
    }
}

 

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

/**
 * @author 
 * @date 2019/5/10 14:14
 */
@Component
public class RunnerOrderTestRunner implements CommandLineRunner{
    @Override
    public void run(String... strings) throws Exception {
        System.out.println("我是一个CommandLineRunner实例");
    }
}

 

结果是 CommandLineRunner实例会在Boot项目启动完成之后执行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值