大致:想要使用Spring Shell,则项目需要是 Spring Boot项目,下面贴出结构和代码

1.POM依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <!--如果原先是Maven项目,不是Spring Boot项目,则这个Parent依赖需要加上-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <groupId>my</groupId>
<artifactId>SpringShellDemo</artifactId>
<version>1.0-SNAPSHOT</version> <name>SpringShellDemo</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url> <properties>
<java.version>1.8</java.version>
</properties> <!--下面是依赖项-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.1.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.1.1.RELEASE</version>
<scope>test</scope>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.1.1.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-starter</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
</dependencies> <!--添加Spring BootMaven插件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
</plugin>
</plugins>
</build> </project>

2.DemoApplication.java Spring Boot启动类

package command;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
} }

3.MyCommand.java 命令类

package command;

import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod; @ShellComponent
public class MyCommandDemo { @ShellMethod("Add two intergers together.")
public int add(int a,int b){
return a+b;
}
}

如果IDE工具是IDEA,执行

mvn clean install -DskipTests:跳过测试,直接安装Install

java -jar target\**.jar(安装的jar包名称):执行jar包

问题:如果启动时出现未找到主程序,则需查看主POM文件是否添加Parent的Spring Boot依赖

Spring Shell简单应用的更多相关文章

  1. 开发Spring Shell应用程序

    2 开发Spring Shell应用程序 向shell提供命令非常简单,需要学习的注解很少.该命令的实现风格与使用依赖注入的应用程序的开发类相同,您可以利用Spring容器的所有特性来实现您的命令类. ...

  2. Spring Shell参考文档

    Spring Shell的核心组件是它的插件模型(plugin model).内置命令(built-in commands)和转换器( converters). 1.1 Plugin Model(插件 ...

  3. Spring Shell介绍

    最近开发中在下遇到了spring-shell开发工具的项目,现在整理了相关文章,以供大家学习 本博客相关的文章均是在Spring Shell 1.2.0的基础上建立   Spring Shell介绍 ...

  4. 自定义Spring Shell

    目录 概述 自定义内置命令 禁用内置命令 覆盖内置命令 自定义命令提示符 自定义命令行选项行为 自定义参数转换器 概述 官网:https://projects.spring.io/spring-she ...

  5. Spring Shell入门介绍

    目录 Spring Shell是什么 入门实践 基础配置 简单示例 注解@ShellMethod 注解@ShellOption 自定义参数名称 设置参数默认值 为一个参数传递多个值 对布尔参数的特殊处 ...

  6. Spring cache简单使用guava cache

    Spring cache简单使用 前言 spring有一套和各种缓存的集成方式.类似于sl4j,你可以选择log框架实现,也一样可以实现缓存实现,比如ehcache,guava cache. [TOC ...

  7. Spring的简单demo

    ---------------------------------------- 开发一个Spring的简单Demo,具体的步骤如下: 1.构造一个maven项目 2.在maven项目的pom.xml ...

  8. 1.Spring IoC简单例子

    Spring IoC简单例子 1.IHelloMessage.java package com.tony.spring.chapter01; public interface IHelloMessag ...

  9. Spring mvc系列一之 Spring mvc简单配置

    Spring mvc系列一之 Spring mvc简单配置-引用 Spring MVC做为SpringFrameWork的后续产品,Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块 ...

随机推荐

  1. 数据库备份与还原c#.net实现

    原文发布时间为:2008-10-25 -- 来源于本人的百度文章 [由搬家工具导入] 数据库备份与还原c#.net实现: 页面上面有 备份,还原,下拉菜单(浏览备份文件夹下面的所有文件名),删除(删除 ...

  2. MySQL介绍及安装&MySQL软件基本管理

    mysql介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是最好 ...

  3. 使用 Apache Lucene 和 Solr 4 实现下一代搜索和分析

    使用 Apache Lucene 和 Solr 4 实现下一代搜索和分析 使用搜索引擎计数构建快速.高效和可扩展的数据驱动应用程序 Apache Lucene™ 和 Solr™ 是强大的开源搜索技术, ...

  4. 快速让你明白Objective-C的语法(和Java、C++对比)

    很多想开发iOS,或者正在开发iOS的程序员以前都做过Java或者C++,当第一次看到Objective-C的代码时都会头疼,Objective-C的代码在语法上和Java, C++有着很大的区别,有 ...

  5. [Bzoj1296][Scoi2009] 粉刷匠 [DP + 分组背包]

    1296: [SCOI2009]粉刷匠 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2184  Solved: 1259[Submit][Statu ...

  6. 怎样解读Caffe源代码

    怎样解读Caffe源代码 导读 Caffe是如今非常流行的深度学习库,能够提供高效的深度学习训练.该库是用C++编写.能够使用CUDA调用GPU进行加速.可是caffe内置的工具不一定能够满足用户的全 ...

  7. java 实现打印当前月份的日历

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcTc0NTQwMTk5MA==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  8. Scrum 每日站会

    站立式会议(Daily Scrum, 有时候我们直接叫做Daily Meeting)是Scrum敏捷软件开发方法学的实践之一,也是团队最容易实施的敏捷实践,实施成本低. 具体做法,团队成员每天固定时间 ...

  9. Evaluate Reverse Polish Notation --leetcode

    原题链接:https://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ 题目大意:给出逆波兰式,然后求其结果. 解题方法:单个栈 ...

  10. Using Python with TurboGears A complete web framework integrating several Python projects

    Using Python with TurboGears TurboGears is a Python web framework based on the ObjectDispatch paradi ...