Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read Console input on spring boot with tomcat

Is it possible to read console input just before the embedded tomcat on the spring boot starts? The supposedly application flow is, request username and password from the user, and that will be used to be able to start the application. It works when using the java -jar command, the problem is when I close the console(SSH on linux) the process stops. I tried searching about it and found out that the process is tied to the console, so I tried using nohup, the problem is I cannot request for console input when using that. Is there any other way?

like image 204
Eldon Hipolito Avatar asked Apr 10 '17 05:04

Eldon Hipolito


People also ask

How do I run a spring boot console application?

You can run your Spring Boot application using your Java IDE or the Command Line in the terminal window. Open the terminal window and change the directory to the root folder of your Spring Boot application. If you list files in this directory, you should see a pom. xml file.


1 Answers

I think this can help you.

public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    //  prompt for the user's name
    System.out.print("Enter your name: ");

    // get their input as a String
    String username = scanner.next();

    System.out.println(username);

    SpringApplication.run(Application.class, args);
}
like image 150
utkusonmez Avatar answered Sep 29 '22 09:09

utkusonmez