Read Console input on spring boot with tomcat

后端 未结 4 1284
轮回少年
轮回少年 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:14

    Get username and password in shell script before executing your java program and pass those as argument to your application.

    #!/bin/bash
    # Ask login details
    read -p 'user: ' uservar
    read -sp 'password: ' passvar
    echo
    

    Now you have user and password you can run java command with nohup and pass user password as jvm properties. You can also pass user and password as program arguments as suggested in other answer.

    Like nohup java -jar abc.jar -Duser=$user -Dpassword=$password

    And fetch these properties using

     String user = System.getProperty("String");
     String password = System.getProperty("password");
    

提交回复
热议问题