eureka叢集-整合config配置中心
需要JAVA Spring Cloud大型企業分散式微服務雲構建的B2B2C電子商務平臺原始碼 一零三八七七四六二六
加入依賴
<dependencies>
<!-- 監控 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 安全驗證 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Netflix -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
application.yml
server:
port: 8881
spring:
application:
name: tms-config
cloud:
config:
server:
git:
uri: 倉庫地址
searchPaths: 目錄
username: 使用者名稱
password: 密碼
label: master
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 30
lease-expiration-duration-in-seconds: 90
metadata-map:
name: tms-config-metadata-map-name
client:
serviceUrl:
defaultZone: http://admin:admin@192.168.1.109:8761/eureka/, http://admin:admin@192.168.1.109:8762/eureka/
# 抓取服務列表時間間隔
registry-fetch-interval-seconds: 30
endpoints:
sensitive: false
shutdown:
enabled: true
sensitive: true
security:
user:
name: admin
password: admin
role: SUPERUSER
management:
context-path: /tms-config
security:
roles: SUPERUSER #角色
# 日誌
logging:
file: logs/logger.log
level:
com.netflix: DEBUG
org.springframework.web: DEBUG
org.springframework.security: INFO
複製程式碼
啟動項
@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class TmsConfigApplication {
public static void main(String[] args) {
SpringApplication.run(TmsConfigApplication.class, args);
}
}
複製程式碼
呼叫者配置 ,注意這裡要用此配置檔名 bootstrap.yml
spring:
application:
name: tms-client
cloud:
config:
label: master
profile: dev
username: admin
password: admin
discovery:
enabled: true
service-id: tms-config
eureka:
client:
serviceUrl:
defaultZone: http://admin:admin@192.168.1.109:8761/eureka/, http://admin:admin@192.168.1.109:8762/eureka/
複製程式碼
讀取配置檔案內容
@RestController
public class TestController {
@Value("${apuserName}")
private String apuserName;
@GetMapping(value = "/hello")
public String hello() {
return apuserName;
}
}
複製程式碼