spring cloud 配置文件:
新建 Spring Boot 项目,引入 config-server 和 starter-web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring cloud config 服务端包 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
通过nacos配置
bootstrap.yml 文件
spring :
profiles :
active : dev
application :
name : basic
bootstrap-dev文件
spring :
cloud :
nacos :
discovery :
server-addr : ${ NACOS_HOST: 10.0.0.0} : ${ NACOS_PORT: 32000 }
namespace : ${ NACOS_NAMESPACE: dev}
config :
prefix : ${ spring.application.name}
server-addr : ${ NACOS_HOST: 10.0.0.0} : ${ NACOS_PORT: 32000 }
file-extension : yml
namespace : ${ NACOS_NAMESPACE: dev}
shared-configs : common.yml
nacos : basic.yml文件
spring :
datasource :
driver-class-name : com.mysql.cj.jdbc.Driver
url : jdbc: mysql: //10.0.0.0: 35000/mysql_data? characterEncoding=UTF- 8&useUnicode=true&useSSL=false&rewriteBatchedStatements=true&serverTimezone=Asia/Shanghai
username : root
password : 123456
hikari :
max-lifetime : 500000
nacos : common.yml文件
server :
port : ${ random.int[ 32768 , 32999 ] }
undertow :
accesslog :
enabled : true
dir : ./logs/${ spring.application.name} /undertow/
buffer-size : 1024
direct-buffers : true
threads :
io : 16
worker : 256
logging :
file :
name : ./logs/${ spring.application.name} /log.log
management :
endpoints :
web :
exposure :
include : '*'
feign :
httpclient :
enabled : false
sentinel :
enabled : true
okhttp :
enabled : true
compression :
request :
enabled : true
response :
enabled : true
client :
config :
default :
connect-timeout : 10000
read-timeout : 10000
spring :
cloud :
config :
override-none : true
rabbitmq :
host : 10.0.0.0
port : 32250
username : admin
password : 123456
redis :
host : 10.0.0.0
port : 32300
database : 0
password : 123456
lettuce :
pool :
max-active : 300
sleuth :
sampler :
probability : 1.0
mvc :
throw-exception-if-no-handler-found : true
jackson :
time-zone : GMT+8
servlet :
multipart :
max-request-size : 50MB
max-file-size : 500MB