Created
November 21, 2019 15:12
-
-
Save seoft/d7ead4ebaf54864316590602510ba55c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package kr.co.seoft.seoft_iot_server; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import java.util.Properties; | |
@SpringBootApplication | |
public class SeoftIotServerApplication { | |
static Logger logger = LoggerFactory.getLogger("SeoftIotServerApplication"); | |
static String EXCEPTION_MESSAGE = "\n>>> Input wrong arguments, Please run like this command\n>>> gradlew bootRun --args'port=3000,password=pwd'"; | |
public static void main(String[] args) throws Exception { | |
int port = 3000; | |
String password = "default"; | |
if (args.length == 0) logger.info("###### Run using default value ######"); | |
else if (args.length == 1) { | |
logger.info("###### Run using user arguments ######"); | |
port = parsePort(args[0]); | |
password = parsePassword(args[0]); | |
} else | |
throw new Exception(EXCEPTION_MESSAGE); | |
SpringApplication application = new SpringApplication(SeoftIotServerApplication.class); | |
Properties properties = new Properties(); | |
properties.put("server.port", port); | |
properties.put("server.password", password); | |
application.setDefaultProperties(properties); | |
application.run(args); | |
logger.info(""); | |
logger.info(""); | |
logger.info("###############################################################"); | |
logger.info("## Swagger UI page : http://127.0.0.1:" + port + "/swagger-ui.html"); | |
logger.info("## port : " + port + " password : " + password); | |
logger.info("###############################################################"); | |
} | |
private static int parsePort(String args) throws Exception { | |
try { | |
String[] params = args.split(","); | |
if (params[0].contains("port")) return Integer.parseInt(params[0].split("=")[1]); | |
else if (params[1].contains("port")) return Integer.parseInt(params[1].split("=")[1]); | |
else throw new Exception(); | |
} catch (Exception e) { | |
throw new Exception(EXCEPTION_MESSAGE); | |
} | |
} | |
private static String parsePassword(String args) throws Exception { | |
try { | |
String[] params = args.split(","); | |
if (params[0].contains("password")) return params[0].split("=")[1]; | |
else if (params[1].contains("password")) return params[1].split("=")[1]; | |
else throw new Exception(); | |
} catch (Exception e) { | |
throw new Exception(EXCEPTION_MESSAGE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment