2、SpringCloud 第一课 Eureka 注册中心

##1、pom.xml 中添加依赖 eureka-server

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.eureka.server.first</groupId>
	<artifactId>one-eurekas-erver</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>one-eurekas-erver</name>
	<description>Demo project for Spring Boot</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.3.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
	</properties>

	<dependencies>
		<!--eureka 服务端,服务注册中心-->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka-server</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-thymeleaf</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

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

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>


----------


##2、application.properties

spring.application.name=one-eurekas-erver


#默认设置下,这个服务注册中心会将自己作为客户端,所以需要禁用它的客户端注册行为 下面5个
# 服务注册中心 端口
server.port=1111
#主机
eureka.instance.hostname=localhost
#这个为注册中心,false代表不向注册中心注册自己 ##直接启动之后会发现这个是空的,说明注册中心没有注册任何服务
eureka.client.register-with-eureka=false 
#注册中心的职责就是维护服务实例,并不需要它去检索服务,所以将它关闭
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/


# 关闭保护机制
#eureka.server.enable-self-preservation=false


logging.file=${spring.application.name}.log

##3、spring boot启动类

@EnableEurekaServer  //开启Eureka服务注册中心的支持,用来供给其他营业进行对话
@SpringBootApplication
public class OneEurekasErverApplication {

	public static void main(String[] args) {
		SpringApplication.run(OneEurekasErverApplication.class, args);
	}
}


##4、测试

浏览器中打开 http://localhost:1111/
这里写图片描述


##5、源码下载

posted @ 2017-05-25 21:22  HealerJean  阅读(60)  评论(0编辑  收藏  举报