seate底层原理_详细讲解微服务SpringCloude

选择依赖:

完整的Pom文件:

4.0.0

com.leyou.demo

eureka-demo

0.0.1-SNAPSHOT

jar

eureka-demo

Demo project for Spring Boot

org.springframework.boot

spring-boot-starter-parent

2.0.1.RELEASE

UTF-8

UTF-8

1.8

Finchley.RC1

org.springframework.cloud

spring-cloud-starter-netflix-eureka-server

org.springframework.cloud

spring-cloud-dependencies

${spring-cloud.version}

pom

import

org.springframework.boot

spring-boot-maven-plugin

spring-milestones

Spring Milestones

https://repo.spring.io/milestone

false

编写启动类:

@SpringBootApplication

@EnableEurekaServer // 声明这个应用是一个EurekaServer

public class EurekaDemoApplication {

public static void main(String[] args) {

SpringApplication.run(EurekaDemoApplication.class, args);

}

}

编写配置:

server:

port: 10086 # 端口

spring:

application:

name: eureka-server # 应用名称,会在Eureka中显示

eureka:

client:

register-with-eureka: false # 是否注册自己的信息到EurekaServer,默认是true

fetch-registry: false # 是否拉取其它服务的信息,默认是true

service-url: # EurekaServer的地址,现在是自己的地址,如果是集群,需要加上其它Server的地址。

defaultZone: http://127.0.0.1😒{server.port}/eureka

6.3.2.将user-service注册到Eureka

注册服务,就是在服务上添加Eureka的客户端依赖,客户端代码会自动把服务注册到EurekaServer中。

我们在user-service-demo中添加Eureka客户端依赖:

先添加SpringCloud依赖:

org.springframework.cloud spring-cloud-dependencies Finchley.RC1 pom import spring-milestones Spring Milestones https://repo.spring.io/milestone false 然后是Eureka客户端:

org.springframework.cloud spring-cloud-starter-netflix-eureka-client 在启动类上开启Eureka客户端功能

通过添加@EnableDiscoveryClient来开启Eureka客户端功能

@SpringBootApplication

@EnableDiscoveryClient // 开启EurekaClient功能

public class UserServiceDemoApplication {

public static void main(String[] args) {

SpringApplication.run(UserServiceDemoApplication.class, args);

}

}

编写配置

server:

port: 8081

spring:

datasource:

url: jdbc:mysql://localhost:3306/mydb01

username: root

password: 123

hikari:

maximum-pool-size: 20

minimum

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值