spingboot启动时运行

spingboot启动时运行

通过实现接口 CommandLineRunner 来实现

package com.hisfront.vh.init;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @file_name:Init1.java
 * @description:
 *
 * @time:2018年5月18日 上午9:56:27
 * @author:sf
 */
@Component
@Order(value = 1)
public class Init1 implements CommandLineRunner {

	@Override
	public void run(String... args) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("============> value=1");
	}
}

package com.hisfront.vh.init;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @file_name:Init2.java
 * @description:
 *
 * @time:2018年5月18日 上午9:56:27
 * @author:sf
 */
@Component
@Order(value = 2)
public class Init2 implements CommandLineRunner {

	@Override
	public void run(String... args) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("============> value=2");
	}
}

效果

============> value=1
============> value=2
原文地址:https://www.cnblogs.com/vmkash/p/9055248.html