微服务中如何搭建eureka注册中心
目前好多公司都在使用微服务技术,微服务中的注册中心应该是最常用的模块,那么怎么通过eureka快速构建注册中心呢?咱们直接上代码。
第一步:前提是maven项目,pom.xml文件是必须的, 通过此文件引入项目中需要的jar包。
<parent>
<artifactId>coca-servers</artifactId>
<groupId>com.yazhou.zhongguo</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>1.0.0</modelVersion>
<artifactId>coca-discovery-server</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
第二步:程序启动程序 DiscoveryApplication;
@EnableEurekaServer
@SpringBootApplication
public class DiscoveryApplication {
public static void main(String[] args) {
SpringApplication.run(DiscoveryApplication.class,args);
}
}
第三步:配置文件bootstrap.yml 如下:
spring:
application:
name: service-discovery
server:
port: 7002
eureka:
dashboard:
path: /ui
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://localhost:7002/eureka
到目前为止,如果你没有其他的特殊要求的话,运行启动类,就可以成功搭建一个注册服务中心了。