Showing posts with label built-in commands. Show all posts
Showing posts with label built-in commands. Show all posts

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

Spring Shell: How to disable built-in commands

Just exclude 'spring-shell-standard-commands' like below.

<dependency>
    <groupId>org.springframework.shell</groupId>
    <artifactId>spring-shell-starter</artifactId>
    <version>2.0.1.BUILD-SNAPSHOT</version>

    <exclusions>
        <exclusion>
            <groupId>org.springframework.shell</groupId>
            <artifactId>spring-shell-standard-commands</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 

 

Previous                                                    Next                                                    Home