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?
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With