当前服务必须是web容器才能触发服务注册,原因如下:
类org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration实现了ApplicationListener方法,只有web容器才能触发执行onApplicationEvent方法
解决方案:
让当前服务变为web容器
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>