JAVA全系列 教程
3762个小节阅读:7095.4k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
pom文件内容如下:
xxxxxxxxxx
<dependencies>
<!--config配置中心服务端-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.2.8.RELEASE</version>
</dependency>
<!--dubbo-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
</dependencies>
配置中心作为一个服务启动后,其它模块都要引用它的配置包括数据库配置、dubbo远程调用组件和sentinel流量防护组件,公共配置文件如下:
xxxxxxxxxx
spring:
#数据源的配置
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://yourIP:8066/TESTDB?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
username: root
password: 123456
#注入数据源的类型 默认的为HikariDataSource
type: com.zaxxer.hikari.HikariDataSource
hikari:
minimum-idle: 5
idle-timeout: 180000 # 空闲连接存活最大时间,默认600000(10分钟)
maximum-pool-size: 10 # 连接池最大连接数,默认是10
auto-commit: true # 此属性控制从池返回的连接的默认自动提交行为,默认值:true
pool-name: MyHikariCP # 连接池名称
max-lifetime: 1800000 # 此属性控制池中连接的最长生命周期,值0表示无限生命周期,默认1800000即30分钟
connection-timeout: 30000 # 数据库连接超时时间,默认30秒,即30000
connection-test-query: SELECT 1
cloud:
nacos:
discovery:
server-addr: yourIP:8848
service: aaa
sentinel:
transport:
dashboard: 127.0.0.1:8078 #sentinel控制台
port: 8719
#dubbo配置
dubbo:
registry:
address: nacos://yourIP:8848
timeout: 10000
protocol:
name: dubbo
port: -1
consumer:
check: false
config-center:
timeout: 10000
项目配置文件如下:
xxxxxxxxxx
#端口
server:
port: 9006
spring:
application:
name: bjsxt-cloud-configserver
profiles:
active: native
cloud:
config:
server:
native:
search-locations: classpath:/config
# springboot中暴露健康检查等断点接口
management:
endpoints:
web:
exposure:
include: "*"
# 暴露健康接口的细节
endpoint:
health:
show-details: always
logging:
pattern:
console: '%d{MM/dd HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n'
主启动类
xxxxxxxxxx
@SpringBootApplication
@EnableDubbo
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class,args);
}
}