Normal development may need to realize the function after the start of the project execution, SpringBoot implementation is to start class implements CommandLineRunner interface code that implements the function on the run method implementation.
public static void main(String[] args) {
SpringApplication.run(CIMServerApplication.class, args);
LOGGER.info("启动 Server 成功");
}
@Override
public void run(String... args) throws Exception {
//获得本机IP
String addr = InetAddress.getLocalHost().getHostAddress();
Thread thread = new Thread(new RegistryZK(addr, appConfiguration.getCimServerPort(),httpPort));
thread.setName("registry-zk");
thread.start() ;
}