OS Windows 10
Java 1.8.0_162
Hello World
build.gradle
buildscript {
ext {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.shell:spring-shell-starter:2.0.0.RELEASE')
}
bootJar {
baseName = 'sample'
}
SampleApplication.java
package sample.spring.shell;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
}
SampleCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello Spring Shell!!");
}
}
> gradle build
> java -jar build\libs\sample.jar
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.8.RELEASE)
(Weggelassen)
shell:>【hello】
Hello Spring Shell!!
shell:>【exit】
(Weggelassen)
>
(
Hallo,
Exit`) nach dem Start von Spring Shell zeigt an, dass der Schlüssel eingegeben wird.Befehl | Erläuterung |
---|---|
clear |
Löschen Sie, was aktuell in der Shell angezeigt wird |
exit , quit |
Verlasse die Shell |
help |
Hilfe erhalten |
script |
Lesen und Ausführen von Befehlen aus einer Datei |
stacktrace |
Stapelverfolgung des letzten Fehlers anzeigen |
Wie es aussieht, wenn Sie Hilfe ausführen
shell:>help
AVAILABLE COMMANDS
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.
Sample Commands
hello: Hello World
Abkürzung | Betriebsdetails |
---|---|
Ctrl + u |
Links vom Cursor löschen |
Ctrl + k |
Rechts vom Cursor entfernen |
Ctrl + a |
Bewegen Sie den Cursor an den Zeilenanfang |
Ctrl + e |
Bewegen Sie den Cursor zum Zeilenende |
Ctrl + w |
Löschen Sie bis zum vorherigen Wort |
Ctrl + d |
Löschen Sie das Zeichen an der Cursorposition |
Ctrl + f |
Bewegen Sie den Cursor um eins |
Ctrl + b |
Bewegen Sie den Cursor zurück |
Alt + f |
Bewegen Sie den Cursor um ein Wort |
Alt + b |
Bewegen Sie den Cursor ein Wort zurück |
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class GreetingCommands {
@ShellMethod("Hello World")
public void hello(String text) {
System.out.println(text);
}
}
Ausführungsergebnis
shell:>【hello "foo bar"】
foo bar
shell:>【hello 'foo bar'】
foo bar
shell:>【hello "foo 'bar'"】
foo 'bar'
shell:>【hello 'foo "bar"'】
foo "bar"
shell:>【hello "foo \"bar\""】
foo "bar"
shell:>【hello 'foo \'bar\''】
foo 'bar'
'
) oder doppelte Anführungszeichen ("
) ein.\
).Entkomme Leerzeichen
shell:>【hello foo\ bar】
foo bar
Ausführungsergebnis
shell:>【hello "abc】
dquote> 【defg】
dquote> 【hijk"】
abc defg hijk
--Wenn Sie "Tab" eingeben, funktioniert die Eingabe an verschiedenen Stellen. --Wenn die Kandidaten angezeigt werden, geben Sie weiterhin "Tab" ein, um den Cursor in der angegebenen Reihenfolge zu den Optionen zu bewegen.
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class GreetingCommands {
@ShellMethod("Hello World")
public void hello(int a, int b, int c) {
System.out.println("a=" + a + ", b=" + b + ", c=" + c);
}
}
Ausführungsergebnis
shell:>【hello \】
> 【--a 10 \】
> 【--b 20 \】
> 【--c 30】
a=10, b=20, c=30
\
) können Sie die Eingabe eines Befehls in mehreren Zeilen beschreiben.SampleCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello Spring Shell!!");
}
}
SampleCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod(value="Hello World", key="hoge")
public void hello() {
System.out.println("Hello Spring Shell!!");
}
}
Ausführungsergebnis
shell:>【hoge】
Hello Spring Shell!!
shell:>【hello】
No command found for 'hello'
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
key
von @ ShellMethod
angeben.SampleCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod(value="Hello World", key={"hoge", "fuga"})
public void hello() {
System.out.println("Hello Spring Shell!!");
}
}
Ausführungsergebnis
shell:>【hoge】
Hello Spring Shell!!
shell:>【fuga】
Hello Spring Shell!!
shell:>【help】
AVAILABLE COMMANDS
Built-In Commands
...
Sample Commands
fuga, hoge: Hello World
key
mehrere Namen festgelegt werden können, können einem Befehl mehrere Namen als Aliase zugewiesen werden.python
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(int a, int b, int c) {
System.out.println("a=" + a + ", b=" + b + ", c=" + c);
}
}
Ausführungsergebnis
shell:>【hello 1 2 3】
a=1, b=2, c=3
shell:>【hello 1 2】
Parameter '--c int' should be specified
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
shell:>【hello a 2 3】
Failed to convert from type [java.lang.String] to type [int] for value 'a'; nested exception is java.lang.NumberFormatException: For input string: "a"
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(int a, int b, int fooBar) {
System.out.println("a=" + a + ", b=" + b + ", fooBar=" + fooBar);
}
}
Ausführungsergebnis
shell:>【hello --a 1 --b 2 --foo-bar 3】
a=1, b=2, fooBar=3
shell:>【hello --foo-bar 3 --a 1 --b 2】
a=1, b=2, fooBar=3
shell:>【hello --b 2 1 3】
a=1, b=2, fooBar=3
- [Argumentname] [Wert]
an--foo-bar
) ersetzt.package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod(value="Hello World", prefix="-")
public void hello(int a) {
System.out.println("a=" + a);
}
}
Ausführungsergebnis
shell:>【hello -a 1】
a=1
-
) ändern, das an den Argumentnamen angehängt ist, wenn Sie den Namen mit dem Attribut Präfix
von @ ShellMethod
angeben.package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(int a, @ShellOption("--foo") int b, @ShellOption({"-h", "--hoge"}) int c) {
System.out.println("a=" + a + ", b=" + b + ", c=" + c);
}
}
Ausführungsergebnis
shell:>【hello --a 1 --foo 2 -h 3】
a=1, b=2, c=3
shell:>【hello --a 1 --foo 2 --hoge 3】
a=1, b=2, c=3
value
als Array angegeben werden kann, können demselben Argument mehrere Namen zugewiesen werden.package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(@ShellOption(defaultValue="9") int a) {
System.out.println("a=" + a);
}
}
Ausführungsergebnis
shell:>【hello】
a=9
shell:>【hello 1】
a=1
defaultValue
von @ ShellOption
kann den Standardwert definieren, wenn dieses Argument nicht angegeben wird.package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
import java.util.Arrays;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(@ShellOption(arity=3) int[] a, int b) {
System.out.println("a=" + Arrays.toString(a) + ", b=" + b);
}
}
Ausführungsergebnis
shell:>【hello 1 2 3 4】
a=[1, 2, 3], b=4
shell:>【hello --a 1 2 3 --b 4】
a=[1, 2, 3], b=4
shell:>【hello 1 --b 4 2 3】
a=[1, 2, 3], b=4
shell:>【hello --a 1 2 --b 4】
Failed to convert from type [java.lang.String] to type [@org.springframework.shell.standard.ShellOption int] for value '--b'; nested exception is java.lang.NumberFormatException: For input string: "--b"
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
shell:>【hello --a 1 2 3 4 --b 5】
Too many arguments: the following could not be mapped to parameters: '4'
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(boolean a) {
System.out.println("a=" + a);
}
}
Ausführungsergebnis
shell:>【hello】
a=false
shell:>【hello --a】
a=true
--Wenn der Argumenttyp "boolean" ist, ändert sich die Spezifikationsmethode im Befehl geringfügig.
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(@ShellOption(defaultValue="true") boolean a, @ShellOption(defaultValue="false") boolean b) {
System.out.println("a=" + a + ", b=" + b);
}
}
Ausführungsergebnis
shell:>【hello】
a=true, b=false
shell:>【hello --a --b】
a=false, b=true
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(@Min(0) @Max(100) int a) {
System.out.println("a=" + a);
}
}
Ausführungsergebnis
shell:>【hello -1】
The following constraints were not met:
--a int : must be greater than or equal to 0 (You passed '-1')
shell:>【hello 0】
a=0
shell:>【hello 100】
a=100
shell:>【hello 101】
The following constraints were not met:
--a int : must be less than or equal to 100 (You passed '101')
--Spring Shell unterstützt die Bean-Validierung. Die Eingabeprüfung kann durchgeführt werden, indem den Methodenargumenten Anmerkungen zu Bean-Validierungsbeschränkungen hinzugefügt werden.
SampleCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
@ShellMethod("Hello World")
public void hello(Hoge hoge) {
hoge.hello();
}
}
Hoge.java
package sample.spring.shell;
public class Hoge {
private final String value;
public Hoge(String value) {
this.value = value;
}
public void hello() {
System.out.println("Hoge(" + this.value + ")");
}
}
HogeConverter.java
package sample.spring.shell;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
public class HogeConverter implements Converter<String, Hoge> {
@Override
public Hoge convert(String source) {
return new Hoge(source);
}
}
Ausführungsergebnis
shell:>【hello Hey】
Hoge(Hey)
org.springframework.core.convert.converter.Converter <S, T>
implementiertpackage sample.spring.shell;
import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
private boolean greeted;
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello!!");
this.greeted = true;
}
@ShellMethod("Good Bye")
public void bye() {
System.out.println("Bye!!");
}
public Availability byeAvailability() {
return this.greeted
? Availability.available()
: Availability.unavailable("you does not greet yet.");
}
}
Ausführungsergebnis
shell:>【bye】
Command 'bye' exists but is not currently available because you does not greet yet.
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
shell:>【help】
AVAILABLE COMMANDS
Built-In Commands
...
Sample Commands
* bye: Good Bye
hello: Hello World
Commands marked with (*) are currently unavailable.
Type `help <command>` to learn more.
shell:>【hello】
Hello!!
shell:>【bye】
Bye!!
bye()
-> byeAvailability()
available ()
erstellt wurdeunavailable ()
erstellt wurdepackage sample.spring.shell;
import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellMethodAvailability;
@ShellComponent
public class SampleCommands {
private boolean greeted;
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello!!");
this.greeted = true;
}
@ShellMethod("Good Bye")
@ShellMethodAvailability("checkByeAvailability")
public void bye() {
System.out.println("Bye!!");
}
public Availability checkByeAvailability() {
return this.greeted
? Availability.available()
: Availability.unavailable("you does not greet yet.");
}
}
@ ShellMethodAvailability
hinzu und geben Sie den Namen der Methode an, die bestimmt, ob sie im Attribut value
gültig oder ungültig ist.package sample.spring.shell;
import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellMethodAvailability;
@ShellComponent
public class SampleCommands {
private boolean greeted;
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello!!");
this.greeted = true;
}
@ShellMethod("Good Bye")
public void bye() {
System.out.println("Bye!!");
}
@ShellMethod("lol")
public void laugh() {
System.out.println("HAHAHAHA!!");
}
@ShellMethodAvailability({"bye", "laugh"})
public Availability checkAvailability() {
return this.greeted
? Availability.available()
: Availability.unavailable("you does not greet yet.");
}
}
Ausführungsergebnis
shell:>【laugh】
Command 'laugh' exists but is not currently available because you does not greet yet.
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
shell:>【bye】
Command 'bye' exists but is not currently available because you does not greet yet.
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
shell:>【hello】
Hello!!
shell:>【laugh】
HAHAHAHA!!
shell:>【bye】
Bye!!
value
anSampleCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class SampleCommands {
private boolean greeted;
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello!!");
this.greeted = true;
}
public boolean isGreeted() {
return this.greeted;
}
}
SomeCommands.java
package sample.spring.shell;
import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellMethodAvailability;
@ShellComponent
public class SomeCommands {
private final SampleCommands sampleCommands;
public SomeCommands(SampleCommands sampleCommands) {
this.sampleCommands = sampleCommands;
}
@ShellMethod("Good Bye")
public void bye() {
System.out.println("Bye!!");
}
@ShellMethod("lol")
public void laugh() {
System.out.println("HAHAHAHA!!");
}
@ShellMethodAvailability
public Availability checkAvailability() {
return this.sampleCommands.isGreeted()
? Availability.available()
: Availability.unavailable("you does not greet yet.");
}
}
Ausführungsergebnis
shell:>【help】
AVAILABLE COMMANDS
Built-In Commands
...
Sample Commands
hello: Hello World
Some Commands
* bye: Good Bye
* laugh: lol
Commands marked with (*) are currently unavailable.
Type `help <command>` to learn more.
GreetingCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class GreetingCommands {
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello!!");
}
@ShellMethod("Good Bye")
public void bye() {
System.out.println("Bye!!");
}
}
CalcCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class CalcCommands {
@ShellMethod("a + b")
public int add(int a, int b) {
return a + b;
}
@ShellMethod("a - b")
public int minus(int a, int b) {
return a - b;
}
}
Ausführungsergebnis
shell:>【help】
AVAILABLE COMMANDS
Built-In Commands
...
Calc Commands
add: a + b
minus: a - b
Greeting Commands
bye: Good Bye
hello: Hello World
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class GreetingCommands {
@ShellMethod(value="Hello World", group="Hello")
public void hello() {
System.out.println("Hello!!");
}
@ShellMethod("Good Bye")
public void bye() {
System.out.println("Bye!!");
}
}
Ausführungsergebnis
shell:>【help】
AVAILABLE COMMANDS
Built-In Commands
...
Greeting Commands
bye: Good Bye
Hello
hello: Hello World
group
von @ ShellMethod
angeben, können Sie die Gruppe für jeden Befehl angeben.GreetingCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellCommandGroup;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
@ShellCommandGroup("My Commands")
public class GreetingCommands {
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello!!");
}
@ShellMethod("Good Bye")
public void bye() {
System.out.println("Bye!!");
}
}
CalcCommands.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellCommandGroup;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
@ShellCommandGroup("My Commands")
public class CalcCommands {
@ShellMethod("a + b")
public int add(int a, int b) {
return a + b;
}
@ShellMethod("a - b")
public int minus(int a, int b) {
return a - b;
}
}
Ausführungsergebnis
shell:>【help】
AVAILABLE COMMANDS
Built-In Commands
...
My Commands
add: a + b
bye: Good Bye
hello: Hello World
minus: a - b
package-info.java
@ShellCommandGroup("my commands")
package sample.spring.shell;
import org.springframework.shell.standard.ShellCommandGroup;
Ausführungsergebnis
shell:>【help】
AVAILABLE COMMANDS
Built-In Commands
...
my commands
add: a + b
bye: Good Bye
hello: Hello World
minus: a - b
--Erstellen Sie package-info.java
und kommentieren Sie das Paket mit @ ShellCommandGroup
--Dann gehören die unter diesem Paket definierten Befehle zu der dort angegebenen Gruppe.
--Wenn für jede der oben genannten Klassen eine Zuordnung vorliegt, hat diese Vorrang.
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
@ShellComponent
public class GreetingCommands {
@ShellMethod(value="Hello World")
public void hello(int a, @ShellOption(defaultValue="9", help="help text") int b) {
System.out.println("Hello!!");
}
}
Ausführungsergebnis
shell:>【help hello】
NAME
hello - Hello World
SYNOPSYS
hello [--a] int [[--b] int]
OPTIONS
--a int
[Mandatory]
--b int
help text
[Optional, default = 9]
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
@ShellComponent
public class GreetingCommands {
private boolean greeted;
@ShellMethod("Hello World")
public void hello() {
System.out.println("Hello!!");
this.greeted = true;
}
@ShellMethod("Good Bye")
public void bye() {
System.out.println("Bye!!");
}
public boolean isGreeted() {
return greeted;
}
}
MyPromptProvider.java
package sample.spring.shell;
import org.jline.utils.AttributedString;
import org.jline.utils.AttributedStyle;
import org.springframework.shell.jline.PromptProvider;
import org.springframework.stereotype.Component;
@Component
public class MyPromptProvider implements PromptProvider {
private final GreetingCommands greetingCommands;
public MyPromptProvider(GreetingCommands greetingCommands) {
this.greetingCommands = greetingCommands;
}
@Override
public AttributedString getPrompt() {
return this.greetingCommands.isGreeted()
? new AttributedString("greeted > ", AttributedStyle.DEFAULT.foreground(AttributedStyle.WHITE))
: new AttributedString("not greeted > ", AttributedStyle.DEFAULT.foreground(AttributedStyle.RED));
}
}
Ausführungsergebnis
not greeted > 【hello】
Hello!!
greeted >
AttributedString
ist eine (Attributed
) Zeichenfolge mit Attributinformationen, und Sie können Zeichenstile (Fett, Farbe usw.) hinzufügen.build.gradle
dependencies {
compile('org.springframework.shell:spring-shell-starter:2.0.0.RELEASE') {
exclude module: 'spring-shell-standard-commands'
}
}
Ausführungsergebnis
shell:>【help】
No command found for 'help'
exit
verschwindet ebenfalls, sodass Sie Ihren eigenen Befehl eingeben müssen, um die Shell zu beenden.package sample.spring.shell;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.StringUtils;
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
String[] disabledCommands = {"--spring.shell.command.help.enabled=false"};
String[] fullArgs = StringUtils.concatenateStringArrays(args, disabledCommands);
SpringApplication.run(SampleApplication.class, fullArgs);
}
}
Ausführungsergebnis
shell:>【help】
No command found for 'help'
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
shell:>【stacktrace】
org.springframework.shell.CommandNotFound: No command found for 'help'
at org.springframework.shell.Shell.evaluate(Shell.java:180)
at org.springframework.shell.Shell.run(Shell.java:134)
...
spring.shell.command. [Befehlsname] .enabled = [true | false]
als Argument angeben, können Sie das Aktivieren / Deaktivieren von integrierten Befehlen steuern.SampleApplication.java
package sample.spring.shell;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.util.StringUtils;
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
String[] disabledCommands = {"--spring.shell.command.help.enabled=false"};
String[] fullArgs = StringUtils.concatenateStringArrays(args, disabledCommands);
SpringApplication.run(SampleApplication.class, fullArgs);
}
}
MyHelpCommand.java
package sample.spring.shell;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.commands.Help;
@ShellComponent
public class MyHelpCommand implements Help.Command {
@ShellMethod("My help command.")
public void help() {
System.out.println("HELP ME!!!!");
}
}
Ausführungsergebnis
shell:>【help】
HELP ME!!!!
Recommended Posts