首页 > 解决方案 > 如何在spring boot中启动应用程序时调用存储过程?

问题描述

我已经在 data.sql 中编写了一个存储过程,现在我想在应用程序启动时调用这个过程。

标签: springspring-bootstored-procedures

解决方案


您可以在主应用程序类中实现CommandLineRunner接口,并且可以覆盖 run 方法,如下所示:-

@SpringBootApplication
public class SpringBootApplication implements CommandLineRunner {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(SpringBootApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {
    //code for stored procedure call goes here
    }
}

推荐阅读