通过Tomcat启动不会注册consul服务问题:

spring cloud 2.1 consul 注册是通过监听WebServerInitializedEvent事件,通过tomcat容器启动服务时监听不到WebServerInitializedEvent事件,Consul无法注册服务,可以加入下面代码:
 

@Component
public class CustomizedEventLinsiners implements ApplicationListener<ContextRefreshedEvent>{
	@Autowired
	ConsulAutoServiceRegistration consulAutoServiceRegistration;
	@Autowired
	ConsulDiscoveryProperties properties;
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		consulAutoServiceRegistration.start();
	}

}

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐