springcloud微服務(wù)服務(wù)發(fā)現(xiàn)eureka服務(wù)和客戶端服務(wù)的搭建
一、服務(wù)端的搭建1、在pom文件中添加eureka服務(wù)依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
2、編寫application.yml 配置
2、編寫application.yml 配置
security:
basic:
enabled: true
user:
name: user
password: password123
server:
port: 8761
eureka:
client:
register-with-eureka: false #只把此服務(wù)當(dāng)成eurekaservice,不要當(dāng)成client
fetch-registry: false #只把此服務(wù)當(dāng)成eurekaservice,不要當(dāng)成client
service-url:
defaultZone: http://user:password123@localhost:8761/eureka
3、在啟動(dòng)類上添加注解
3、在啟動(dòng)類上添加注解
@SpringBootApplication
@EnableEurekaServer
就可以啟動(dòng)服務(wù)發(fā)現(xiàn)的服務(wù)端程序了。
二、客戶端的搭建
1、在pom文件中添加依賴
就可以啟動(dòng)服務(wù)發(fā)現(xiàn)的服務(wù)端程序了。
二、客戶端的搭建
1、在pom文件中添加依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
2、編寫application.yml 配置
2、編寫application.yml 配置
server:
port: 7901
session-timeout: 30
tomcat.max-threads: 0
tomcat.uri-encoding: UTF-8
spring:
application:
name: a-microservice-consumer-movie
logging:
level:
root: INFO
com.example.demo: debug
eureka:
client:
serviceUrl:
defaultZone: http://user:password123@localhost:8761/eureka
instance: #eureka管理頁面客戶端服務(wù)的地址顯示實(shí)際IP
prefer-ip-address: true #默認(rèn)是false
3、在啟動(dòng)類添加注解
3、在啟動(dòng)類添加注解
@SpringBootApplication
@EnableEurekaClient //針對Eureka服務(wù)注冊使用
//@EnableDiscoveryClient //可以對其他服務(wù)注冊軟件使用
這樣客戶端配置完畢,先啟動(dòng)服務(wù)端,再啟動(dòng)客戶端,服務(wù)端就可以自動(dòng)發(fā)現(xiàn)客戶端服務(wù)了。
這樣客戶端配置完畢,先啟動(dòng)服務(wù)端,再啟動(dòng)客戶端,服務(wù)端就可以自動(dòng)發(fā)現(xiàn)客戶端服務(wù)了。