参考:
https://www.cnblogs.com/skyblog/p/5133752.html
http://blog.csdn.net/u012734441/article/details/78256256?locationNum=1&fps=1
https://www.cnblogs.com/ncjava/p/7149593.html(eureka高可用)
http://blog.csdn.net/lc0817/article/details/54375802(eureka常见错误及更多配置)。
开始集成eureka,服务端
1. pom.xml中添加
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
2. 启动类
@SpringBootApplication
@EnableEurekaServer
public class ChilliApplication {
public static void main(String[] args) {
SpringApplication.run(ChilliApplication.class, args);
}
}
3. 配置文件
server:
port: 55580 spring:
application:
name: asfood-chilli
profiles:
active: dev eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ logging:
file: ./logs/chilli.log
4. 客户端配置
添加同样的pom依赖;
配置文件中添加
eureka:
client:
serviceUrl:
defaultZone: http://localhost:55580/eureka/
启动类添加注释:@EnableEurekaClient
至于@EnableEurekaClient和@EnableDiscoveryClient的区别可以百度,建议的是,使用eureka就用EnableEurekaClient。
可以通过访问eureka客户端查看已经注册的服务。