Spring系列学习之Spring Shell命令行
2018-12-22 22:31
387 查看
英文原文:https://projects.spring.io/spring-shell/
目录
Spring Shell项目提供了一个交互式shell,允许您使用基于Spring的编程模型插入自己的自定义命令。
介绍
Spring Shell项目的用户可以通过依赖Spring Shell jar并添加他们自己的命令(作为spring bean上的方法)轻松构建一个功能齐全的shell(也就是命令行)应用程序。创建命令行应用程序可能是有用的,例如与项目的REST API交互,或使用本地文件内容。
特性
Spring Shell的功能包括:
- 一个简单的,注释驱动的编程模型,用于提供自定义命令
- 使用Spring Boot自动配置功能作为命令插件策略的基础
- 选项卡完成,着色和脚本执行
- 自定义命令提示符,shell历史文件名,结果和错误的处理
- 基于域特定标准动态启用命令
- 与bean验证API集成
- 已经内置命令,如清晰的屏幕,华丽的帮助,退出
- ASCII艺术表,带格式,对齐,花式边框等。
快速开始
在项目中使用spring-shell的推荐方法是使用依赖关系管理系统 - 下面的代码片段可以复制并粘贴到您的构建中。 需要帮忙? 请参阅我们的Maven和Gradle构建入门指南。(可导航到英文页面选择对应的版本和依赖方式)
Maven
[code]<dependencies> <dependency> <groupId>org.springframework.shell</groupId> <artifactId>spring-shell-starter</artifactId> <version>2.0.0.RELEASE</version> </dependency> </dependencies>
Gradle
[code]dependencies { compile 'org.springframework.shell:spring-shell-starter:2.0.0.RELEASE' }
然后创建一个可以作为调用的简单命令
[code]shell:>translate "hello world!" --from en_US --to fr_FR bonjour monde!
假设您可以访问某些与Locales一起使用的翻译服务:
[code]package foo; @ShellComponent public class TranslationCommands { private final TranslationService service; @Autowired public TranslationCommands(TranslationService service) { this.service = service; } @ShellMethod"Translate text from one language to another.") public String translate( @ShellOption(mandatory = true) String text, @ShellOption(mandatory = true, defaultValue = "en_US") Locale from, @ShellOption(mandatory = true) Locate to ) { // invoke service return service.translate(text, from, to); } }
Spring Shell
Release
Documentation
2.0.1
2.0.0
示例和相关项目
阅读更多相关文章推荐
- Spring系列学习之Spring Could CLI 命令行
- Linux命令行与Shell脚本编程[学习笔记1]
- 下一个系列学习列表Spring.net+NHibernate+MVC
- MacOS系统使用系列-3.Mac命令行命令学习
- LFCS 系列第十讲:学习简单的 Shell 脚本编程和文件系统故障排除
- Liunx 命令行与shell脚本编程大全 第五章学习笔记(Vim 编辑器使用详解 解释+图示)
- Spring学习系列
- 深入学习spring-boot系列(二)--使用spring-data-jpa
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- 深入学习spring-boot系列(三)--使用thymeleaf模板
- spring学习系列 --- AOP学习
- spring学习系列 -- 定时器三 两种定时器的比较
- 分布式缓存技术redis学习系列(六)—— 深入理解Spring Redis的使用
- 分布式缓存技术redis学习系列----深入理解Spring Redis的使用
- MyBatis学习系列十:Spring集成
- Spring.Net学习系列一: 统一异常处理
- SpringMVC学习系列(12) 完结篇 之 基于Hibernate+Spring+Spring MVC+Bootstrap的管理系统实现
- Spring Boot系列学习
- SpringBoot学习系列 | Spring @Async 异步线程池用法梳理
- 深入学习spring-boot系列(二)--使用spring-data-jpa