Sunday, 14 February 2021

Spring Shell: Override built-in commands

By implementing <Command>.Command interface, we can override the behavior of built-in command.

 

For example, below snippet overrides the built-in ‘exit’ command behavior.

import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.commands.Quit;

@ShellComponent
public class CustomExitCommand implements Quit.Command {

	@ShellMethod(value = "Exit the shell.", key = {"quit", "exit", "terminate"})
	public void quit() {
		System.out.println("Exiting the Application");
		System.out.println("Good Bye!!!!!!!!");
		System.exit(0);
		
	}
}

 When you execute the command ‘exit’, system will print the messages and exit from the application.

shell:>exit
Exiting the Application
Good Bye!!!!!!!!

 

             

Previous                                                    Next                                                    Home

No comments:

Post a Comment