server 注册中心
client 80端口
配置:
server:
port: 80
spring:
http:
multipart:
enabled: true
max-file-size: 100MB
max-request-size: 100MB
application:
name: cloudClient-80
# mvc:
# static-path-pattern: /static/libs/**
# resources:
# static-locations: classpath:/WEB-INF/classes/static/
eureka:
instance:
#注册服务的时候使用服务的ip地址
prefer-ip-address: true
#心跳设置,告诉服务器该实例仍在使用
lease-renewal-interval-in-seconds: 5
#告诉服务器如果10秒内未发送任何续约请求,则关闭该客户端
lease-expiration-duration-in-seconds: 10
client:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://127.0.0.1:8888/eureka/
# 抓取服务列表
registry-fetch-interval-seconds: 30
zuul:
sensitive-headers: "*"
max:
host:
connections: 500
socket-timeout-millis: 60000
connect-timeout-millis: 60000
# ignored-services: app3 # 需要忽视的服务(配置后将不会被路由)
routes:
app:
path: /app/**
prefix: /app
service-id: client-app
url: http://127.0.0.1:8081
strip-prefix: false
app1:
path: /app1/**
service-id: client-app1
url: http://47.103.131.182:9007
strip-prefix: false
web:
path: /**
service-id: client-web
url: http://127.0.0.1:8082
strip-prefix: false//这里注意 /** 要放最后,他们的关系是if else 如果放前面,会被/**拦截到,下面的带前缀的都不会访问到
ribbon:
ReadTimeout: 10000
ConnectTimeout: 10000
MaxAutoRetries: 0
MaxAutoRetriesNextServer: 1
eureka:
enabled: true
hystrix:
command:
default:
execution:
timeout:
enabled: true
isolation:
thread:
timeoutInMilliseconds: 60000
logging:
# 保存日志文件目录路径
file: C:\\app.log
# 日志级别
level:
# 配置spring web日志级别
org.springframework.web: ERROR
其他子项目:
eureka:
instance:
#注册服务的时候使用服务的ip地址
prefer-ip-address: true
#心跳设置,告诉服务器该实例仍在使用
lease-renewal-interval-in-seconds: 5
#告诉服务器如果10秒内未发送任何续约请求,则关闭该客户端
lease-expiration-duration-in-seconds: 10
EurekaServerConnectTimeoutSeconds: 10
client:
time:
healthcheck:
enabled: true
serviceUrl:
defaultZone: http://47.103.131.182:8888/eureka/
# 抓取服务列表
registry-fetch-interval-seconds: 30
eureka-server-connect-timeout-seconds: 15
ribbon:
eureka:
enabled: false
#设置端口
server:
port: 自定义
context-path: /app1
spring:
application:
name: client-app1
#数据源
datasource:
url: jdbc:mysql://127.0.0.1:3306/数据库?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true
username: root
password: 123
driver-class-name: com.mysql.jdbc.Driver
platform: mysql
type: com.alibaba.druid.pool.DruidDataSource
# 初始化时建立物理连接的个数
initial-size: 5
# 最大连接池数量
max-active: 20
# 最小连接池数量
min-idle: 5
# 获取连接时最大等待时间
max-wait: 60000
# 是否缓存preparedStatement,也就是PSCache。
pool-prepared-statements: false
# 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。
max-pool-prepared-statement-per-connection-size: -1
# 用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。
validation-query: SELECT 1 FROM DUAL
# 单位:秒,检测连接是否有效的超时时间。
validation-query-timeout: 1
# 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
test-on-borrow: false
# 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
test-on-return: false
# 建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
test-while-idle: true
# 有两个含义:1) Destroy线程会检测连接的间隔时间,如果连接空闲时间大于等于minEvictableIdleTimeMillis则关闭物理连接。2) testWhileIdle的判断依据,详细看testWhileIdle属性的说明
time-between-eviction-runs-millis: 6000
# 连接保持空闲而不被驱逐的最小时间
min-evictable-idle-time-millis: 1800000
# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
filters: stat,wall,log4j
# 通过connectProperties属性来打开mergeSql功能;慢SQL记录
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
cache:
type: redis
redis:
time-to-live: 100 #缓存超时时间ms
cache-null-values: false #是否缓存空值
redis:
host: 127.0.0.1
port: 8889
password: admin
pool:
max-active: 8
max-idle: 300
min-idle: 5
max-wait: -1
tomcat:
test-while-idle: true
mybatis-plus:
# type-aliases-package: com.**.**.model
# mapper-locations: com/**/**/mapper/xml/*.xml
global-config:
#主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
id-type: 0
#字段策略
field-strategy: 1
#刷新mapper 调试神器
refresh-mapper: true
#数据库大写下划线转换
capital-mode: true
# Sequence序列接口实现类配置
key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
configuration:
map-underscore-to-camel-case: false
cache-enabled: true
#freemarker配置
freemarker:
settings:
template_update_delay: 0
defaultEncoding: UTF-8
url_escaping_charset: UTF-8
locale: zh_CN
boolean_format: true,false
datetime_format: yyyy-MM-dd HH:mm:ss
date_format: yyyy-MM-dd
time_format: HH:mm:ss
number_format: 0.######
whitespace_stripping: true
classic_compatible: true
mybatis:
configuration:
map-underscore-to-camel-case: true
#上传文件大小
http:
multipart:
max-file-size: 10MB
max-request-size: 100MB
logging:
level:
com.**.**.mapper: debug//自己的项目路径
#自定义配置 上传路径
picture_Po:
pictureLocal: E:/upload/
这里要注意:
1、注册中心,每个子项目的访问前缀配置为:/前缀/** ,/**放最后 ,带前缀的放前面
2、访问原理:所有项目(包括client)注册到注册中心后,访问client(80端口),通过前缀判断进入哪一个子项目,子项目要在tomcat配置访问前缀
3、其他springcloud如何创建server client部分,自己参照百度即可