1.搭建父模块 hrm-parent
1.配置pom
<!--springboot仲裁中心-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</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>Finchley.SR1</spring-cloud.version>
</properties>
<!-- 管理springcloud的版本-->
<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>
2.搭建中间模块 hrm-support-parent
什么都不用做
3.搭建eureka
1.配置pom
<dependencies>
<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>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
<!-- 间接继承parent不需要指定执行的入口类,和repackage-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
2.配置yml
application.yml
spring:
application:
name: hrm-eureka
bootstrap.yml
spring:
application:
name: hrm-eureka
server:
port: 1010
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ #单机配置
3.写入口类
@SpringBootApplication
@EnableEurekaServer
public class Eureka1010Application {
public static void main(String[] args) {
SpringApplication.run(Eureka1010Application.class,args);
}
}
3.搭建config server
1.创建码云库
2.构建一个能够提示额配置库
建立假的springboot项目
1.配置pom
<!--springboot仲裁中心-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.RELEASE</version>
</parent>
<dependencies>
<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>
2.yml
spring:
profiles:
active:
- dev
---
server:
port: 3355
spring:
profiles: dev #开发环境
application:
name: MICROSERVICE-USER-DEV
---
server:
port: 3355
spring:
profiles: test #测试环境
application:
name: MICROSERVICE-USER-TEST
3.把配置库项目初始化到码云,并且删除本地,从码云进行导入。
3.在中间模块下面创建configServer模块
1.配置pom
<!--springboot支持-->
<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>
</dependency>
<!--eureka客户端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--配置中心支持-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
2.yml
server:
port: 1020
eureka:
client:
service-url:
defaultZone: http://localhost:1010/eureka
instance:
prefer-ip-address: true
spring:
application:
name: hrm-config-server
cloud:
config:
server:
git:
uri: https://gitee.com/qyhdd/hrm-config.git
username: git账号
password: git密码
search-paths: src/main/resources # 如果不是在根路径下面需要加搜索地址
3.入口类
@SpringBootApplication
@EnableEurekaClient
@EnableConfigServer
public class ConfigServer1020Application {
public static void main(String[] args) {
SpringApplication.run(ConfigServer1020Application.class,args);
}
}
4.搭建Zuul GateWay
1.配置pom
<!-- springBoot支持 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring boot 测试 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<!-- Eureka 客户端依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!-- zuul支持-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<!--配置中心支持-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
2.配置yml
application.yml
spring:
application:
name: zuul-gateway
bootstap
spring:
profiles:
active: dev
cloud:
config:
name: application-zuul
profile: ${spring.profiles.active} #环境 java -jar -D xxx jar
label: master #分支
discovery: #configserver集群
enabled: true #从eureka上面找配置服务
service-id: hrm-config-server #指定服务名
#uri: http://127.0.0.1:1299 #配置服务器 单机配置
eureka: #eureka不能放到远程配置中
client:
service-url:
defaultZone: http://localhost:1010/eureka #告诉服务提供者要把服务注册到哪儿 #单机环境
instance:
prefer-ip-address: true #显示客户端真实ip
3.入口类
@SpringBootApplication
@EnableZuulProxy
public class Zuul1030Application {
public static void main(String[] args) {
SpringApplication.run(Zuul1030Application.class,args);
}
}