Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 63 章 Spring Cloud Netflix

目录

63.1. Eureka Server
63.1.1. Maven
63.1.2. Application
63.1.3. application.properties
63.1.4. 检查注册服务器
63.2. Eureka Client
63.2.1. Maven
63.2.2. Application
63.2.3. RestController
63.2.4. application.properties
63.2.5. 测试
63.3. Feign client
63.3.1. Maven
63.3.2. Application
63.3.3. interface
63.3.4. application.properties
63.3.5. 测试
63.3.6. fallback
63.4. 为 Eureka Server 增加用户认证
63.4.1. Maven
63.4.2. application.properties
63.4.3. Eureka Client
63.4.4. Feign Client
63.5. Eureka 配置项
63.5.1. /eureka/apps
63.5.2. Eureka instance 配置项
63.5.3. Eureka client 配置项
63.5.4. Eureka Server配置项
63.6. ribbon
63.6.1.
63.6.2. LoadBalancerClient 实例
63.6.3. Ribbon 相关配置
63.7. 获取 EurekaClient 信息
63.8. Zuul
63.8.1. Maven
63.8.2. EnableZuulProxy
63.8.3. application.yml
63.8.4. 负载均衡配置

63.1. Eureka Server

63.1.1. Maven

			
<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>cn.netkiller.spring.cloud</groupId>
	<artifactId>netflix.eureka.server</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>eureka.server</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.7.RELEASE</version>
		<relativePath />
	</parent>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-netflix</artifactId>
				<version>1.3.5.RELEASE</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<dependencies>
		<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>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<skip>true</skip>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>			
			
			

63.1.2. Application

			
package cn.netkiller.spring.cloud.netflix.eureka.server;

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

@SpringBootApplication
@EnableEurekaServer
public class Application {
	public static void main(String[] args) {
		System.out.println("Hello World!");
		// new SpringApplicationBuilder(Application.class).web(true).run(args);
		SpringApplication.run(Application.class, args);
	}
}
			
			

63.1.3. application.properties

			
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

logging.level.com.netflix.eureka=OFF
logging.level.com.netflix.discovery=OFF
			
			

63.1.4. 检查注册服务器

http://localhost:8761