简体   繁体   中英

SpringBoot application without a rest controller

i´m new to spring and i´m currently working on a spring application to migrate data between 2 databases.

My question is, how is it going to run?? I mean, using spring, how to let spring knows where the migration process will start?

For example, assuming that i have 3 tables (Customer, Product and Invoices).

I´ll work on the classes to migrate first all data from customer, then product and finally invoices.

I´m confused on how spring will manage this when it starts.

Tks in advance.

As @Marged suggested, A CommandLineRunner application would just achieve what you're looking for:

@SpringBootApplication
public class YourMigrationApplication implements CommandLineRunner {
 
    public static void main(String[] args) {
        // Application starts
        SpringApplication.run(SpringBootConsoleApplication.class, args);
        // Migration finished
    }
 
    @Override
    public void run(String... args) {
        // Migrate Customer data
        // Migrate Product data
        // Migrate Invoice data
    }
}

When the migrate invoice data step completes, your application will exit since there's nothing left to run. (And you don't have any controllers etc. to continue listen to).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM