使用tomcat在Spring Boot上读取控制台输入 [英] Read Console input on spring boot with tomcat

查看:599
本文介绍了使用tomcat在Spring Boot上读取控制台输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Spring Boot上的嵌入式tomcat启动之前读取控制台输入?假定的应用程序流程是从用户那里请求用户名和密码,这将被用来启动应用程序.使用java -jar命令时它可以工作,问题是当我关闭控制台(在Linux上为SSH)时,进程停止了.我尝试搜索它,发现进程与控制台绑定,因此我尝试使用nohup,问题是使用该命令时我无法请求控制台输入.还有其他办法吗?

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?

推荐答案

我认为这可以为您提供帮助.

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);
}

这篇关于使用tomcat在Spring Boot上读取控制台输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆