【JAVA】springboot的CommandLineRunner

平常开发中有可能需要实现在项目启动后执行的功能,SpringBoot实现方案就是启动类实现CommandLineRunner接口,实现功能的代码放在实现的run方法中。

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

猜你喜欢

转载自blog.csdn.net/cheidou123/article/details/93529132
今日推荐