Spring mvc 如何在我的应用程序中运行特定的SpringBoot CommandLineRunner?

Spring mvc 如何在我的应用程序中运行特定的SpringBoot CommandLineRunner?,spring-mvc,spring-boot,Spring Mvc,Spring Boot,我遵循为我的SpringBoot应用程序创建CommandLineRunner的步骤。我不明白的是,如何在ma应用程序中运行此特定命令?在此特定示例中,有一个FileProcessingCommandLine类,实现了“run”方法。现在,我如何从命令提示符下运行它?一个无法手动运行的命令。Spring框架负责运行此方法 您应该用Spring的@组件注释标记您的类,以便@SpringBootApplication自动拾取该注释 如果您的类实现了Spring Boot的CommandLineRun

我遵循为我的SpringBoot应用程序创建CommandLineRunner的步骤。我不明白的是,如何在ma应用程序中运行此特定命令?在此特定示例中,有一个FileProcessingCommandLine类,实现了“run”方法。现在,我如何从命令提示符下运行它?

一个无法手动运行的命令。Spring框架负责运行此方法

您应该用Spring的
@组件
注释标记您的类,以便
@SpringBootApplication
自动拾取该注释

如果您的类实现了Spring Boot的
CommandLineRunner
,那么它将在创建和注册所有bean之后运行

@Component
public class FirstCommandLineRunner implements CommandLineRunner {


    @Override
    public void run(String... strings) throws Exception {
        System.out.println("hello world");
    }
}

我明白了,可能是我理解错了。我正在试图找到一种方法,如何从控制台手动运行一些命令,以便查看所有spring环境,如“数据导入”、一些维护任务等。如果您想检查应用程序的运行状况,您可以检查它,它非常适合维护。对于数据导入,您可以在加载应用程序时使用
CommandLineRunner
——执行初始数据导入。