是否可以在 spring boot 上的嵌入式 tomcat 启动之前读取控制台输入?所谓的应用程序流程是,向用户请求用户名和密码,这将用于启动应用程序。它在使用 java -jar
命令时有效,问题是当我关闭控制台(Linux 上的 SSH)时进程停止。我尝试搜索它并发现该进程与控制台相关联,因此我尝试使用 nohup
,问题是我在使用时无法请求控制台输入。有没有其他办法?
最佳答案
我认为这可以帮助你。
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);
}
关于java - 使用tomcat在spring boot上读取控制台输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43315607/