服务注册中心 :eureka-server
新建一个springboot项目:eureka-server,其pom.xml配置如下:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
想要实现一个服务注册中心的功能非常简单,只需要在项目的启动类EurekaServerApplication上使用@EnableEurekaServer注解即可
1 @EnableEurekaServer
2 @SpringBootApplication
3 public class EurekaServerApplication{
4
5 public static void main(String[] args) {
6 new SpringApplicationBuilder(EurekaServerApplication.class)
7 .web(true).run(args);
8 }
9 }
默认情况下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以我们需要禁用它的客户端注册行为,只需要在application.properties配置文件中增加如下信息:
1 spring.application.name=eureka-server
2 server.port=1001
3 eureka.instance.hostname=localhost
4 eureka.client.register-with-eureka=false
5 eureka.client.fetch-registry=false
启动EurekaServerApplication,访问 http://localhost:9001/可以看到Eureka的页面,从红框的位置可以看到没有任务服务实例注册到当前的服务注册中心
更多请见:http://www.mark-to-win.com/tutorial/51206.html