Sping Cloud 学习之一 搭建服务注册中心

注:参考《spring cloud实践》第三章 服务治理 Spring Cloud Eureka

spring boot 版本 1.3.7 

1、添加 spring boot Eureka 依赖

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

		<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>Brixton.SR5</version>
				<scope>import</scope>
				<type>pom</type>
			</dependency>
		</dependencies>
	</dependencyManagement>

2、使用@EnableEurekaServer 注解启动一个服务注册中心提供给其他应用对话

package com.hdsxtech.eurekaserver;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
	public static void main(String[] args) {
		//SpringApplication.run(EurekaServerApplication.class, args);
		new SpringApplicationBuilder(EurekaServerApplication.class)
				.web(true).run(args);
	}
}

3、properties 配置

server.port=1111

eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false # 让他别注册自己
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

4、在浏览器中输入地址http://localhost:1111,看到如下页面表示注册中心服务搭建成功


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页