Wie verwaltete ich die Befehle in einer Spring -Shell -Anwendung dynamisch?Java

Java-Forum
Anonymous
 Wie verwaltete ich die Befehle in einer Spring -Shell -Anwendung dynamisch?

Post by Anonymous »

Ich erstelle eine Befehlszeilenschnittstellenanwendung mit Spring Shell. Jeder Befehl ist in seiner eigenen separaten Klasse definiert.
1 Klasse mit dem Namen Foo. /> Wenn die Anwendung beginnt, sind nur Befehle "a" und "e" verfügbar. "a" wird wieder verfügbar). Diese FOO -Instanz steht den Befehlen "B", "C" und "D" zur Verfügung. Nach dem Befehl "D" wird die FOO -Instanz "zerstört" < /p>
< /li>
< /ol>
Was ich bisher geschafft habe, ist die erste Anforderung, wie im folgenden Code gezeigt. < /P>

Code: Select all

package com.example.test;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringApplication;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.Availability;
import org.springframework.shell.standard.ShellMethodAvailability;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Autowired;

@ShellComponent
class StartCommand extends AvailabilityHandler {

@ShellMethod(key="a")
@Bean
public Foo a(){
System.out.println("Command \"a\" executed.");
return new Foo();
}
}

@ShellComponent
class FirstInBetweenCommand extends AvailabilityHandler {

@ShellMethod(key="b")
@ShellMethodAvailability("commandAHasRun")
public void b(){
System.out.println("Command \"b\" executed.");
}
}

@ShellComponent
class SecondInBetweenCommand extends AvailabilityHandler {

@ShellMethod(key="c")
@ShellMethodAvailability("commandAHasRun")
public void c(){
System.out.println("Command \"c\" executed.");
}
}

@ShellComponent
class StopCommand extends AvailabilityHandler {

@ShellMethod(key="d")
@ShellMethodAvailability("commandAHasRun")
public void d(){
System.out.println("Command \"d\" executed.");
}
}

@ShellComponent
class AsideCommand extends AvailabilityHandler {

@ShellMethod(key="e")
public void e(){
System.out.println("Command \"e\" executed.");
}
}

class Foo {

Foo(){
System.out.println("Foo bean created");
}
}

@SpringBootApplication
public class Demo{
public static void main(String[] args){
SpringApplication.run(Demo.class, args);
}
}

abstract class AvailabilityHandler {
public Availability commandAHasRun(){
System.out.println("Check command availability");
return Availability.unavailable("Command \"a\" has not run yet");
}
}
So implementieren Sie die beiden anderen Regeln?>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post