how to build console command in spring boot web application using spring shell?

后端 未结 2 1566
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 12:37

I have created restfull web application using spring boot web starter which works well. I am able to access it through urls.

But I have requirement to create console co

2条回答
  •  无人共我
    2021-02-07 13:03

    It sounds like you have two distinct use cases here: running scheduled tasks, and running commands manually. From my understanding, Spring Shell isn't part of the Boot ecosystem. You can write a Spring Shell application that is external to your Boot Web app, but it's not going to embed within it. At least from my experience.

    For the first case of scheduled tasks, you should look at Spring's Scheduler. You should be able to configure a Spring application (Boot or normal) that has a Task Scheduler within it. Then you can configure your Tasks that can be scheduled, letting the scheduler do the work.

    For manually executing the commands, you do have a few options here. If you use Spring Shell, assume it's running in its own process, external to the Spring Boot process. You would need to have the Shell app call into the Boot application (presuming that's where you want to work to occur) using remote method invocation technologies (eg, RMI, REST, etc).

    An alternative to Spring Shell is to embed a remote shell into your Boot application. Essentially, you can use SSH to connect to your Boot application and define commands in a similar fashion as Spring Shell. The benefit is that this is in the same process as the Boot application. So you can inject the Task Scheduler and run the same Tasks manually as are scheduled. This might be a good option if you want to manually kick of the same Tasks are being scheduled. Doco for the remote console is here.

    Hope this helps

提交回复
热议问题