spring boot启动自动执行的代码

版权声明: https://blog.csdn.net/qq_32157851/article/details/80679830
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class MystartRunner implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
         System.out.println("<<<<<<<<<<<<这个是测试CommandLineRunn接口>>>>>>>>>>>>>>");

    }

}


1)新建一个类实现CommandLineRunner接口,

2)在类上打一个@Component的注解

3)将要执行的方法写入到run方法中去

猜你喜欢

转载自blog.csdn.net/qq_32157851/article/details/80679830