Spring Shell

                                                        Spring Shell

看到Spring官网中有一个spring shell今天又空就去了解了一下Spring shell的内容。

Spring Shell 用途:有时并非所有的应用程序都需要一个花哨的Web用户界面,使用交互式终端与应用程序进行交互是完成任务的最合适的方式。

Spring Shell允许用户轻松创建这样一个可运行的应用程序,用户将输入文本命令,直到程序终止时才会执行。 Spring Shell项目提供了创建这种REPL(读取,评估,打印循环)的基础结构,使开发人员可以使用熟悉的Spring编程模型专注于命令的实现。

诸如解析,TAB完成,输出着色,花式ASCII艺术表格显示,输入转换和验证等高级功能都是免费的,开发人员只需要关注核心命令逻辑。

总结一下就是:Spring shell 可以实现一个简单的命令交互,你使用这个只需要专注于逻辑就可以了。

代码:


@ShellComponent
public class AddShell {

  @ShellMethod("Add two integers together.")
  public int add(int a, int b) {
    return a + b;
  }
}

maven依赖:

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>org.springframework.shell</groupId>
			<artifactId>spring-shell-starter</artifactId>
			<version>2.0.0.BUILD-SNAPSHOT</version>
		</dependency>

</dependencies>

运行Spring boot项目后效果如下:

shell:>help
AVAILABLE COMMANDS

Add Shell
        add: Add two integers together.

Built-In Commands
        clear: Clear the shell screen.
        exit, quit: Exit the shell.
        help: Display help about available commands.
        script: Read and execute commands from a file.
        stacktrace: Display the full stacktrace of the last error.


shell:>clear
shell:>

 

转载于:https://my.oschina.net/QAAQ/blog/1561099

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值