十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章将为大家详细讲解有关Spring Shell应用程序如何开发,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
向shell提供命令非常简单,需要学习的注解很少。该命令的实现风格与使用依赖注入的应用程序的开发类相同,您可以利用Spring容器的所有特性来实现您的命令类。
标记接口
创建命令的第一步是实现标记接口CommandMarker,并使用Spring的@Component注解对类进行注解(注意一个JIRA问题:提供@CliCommand元注解避免使用标记接口)。使用helloworld示例应用程序中的代码为例,HelloWorldCommands类的代码如下所示:
@Component public class HelloWorldCommands implements CommandMarker { // use any Spring annotations for Dependency Injection or other Spring interfaces // as required. // methods with @Cli annotations go here }