Read Console input on spring boot with tomcat

后端 未结 4 1260
轮回少年
轮回少年 2021-02-20 01:12

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,

4条回答
  •  离开以前
    2021-02-20 01:15

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

提交回复
热议问题