我想将输出存储在变量端口s,s1中,然后在日志信息中的application.properties文件中使用它
logging.pattern.console =%d {yyyy-MM-dd HH:mm:ss.SSS} ----%msg%n
我不断收到nullpointerexception错误 @SpringBootApplication 公共类RegistrationFormApplication / *实现ApplicationListener * / {
static ServletWebServerInitializedEvent embeddedServletContainerInitializedEvent;
static {
embeddedServletContainerInitializedEvent = null;
}
static Logger logger = LogManager.getLogger(RegistrationFormApplication.class);
public static void main(String[] args) {
int port = embeddedServletContainerInitializedEvent.getApplicationContext().getWebServer().getPort();
// logger.info(端口); System.out.println( “ Port” + EmbeddedServletContainerInitializedEvent.getApplicationContext()。getWebServer()。getPort());
try {
String s = InetAddress.getLocalHost().getHostAddress();
System.out.println("HOST Address " + InetAddress.getLocalHost().getHostAddress());
String s1 = InetAddress.getLocalHost().getHostName();
System.out.println("Host Name " + InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException e) {
}
SpringApplication.run(RegistrationFormApplication.class, args);
}
}