spring boot 1.x配置,不断完善中
spring boot是典型的约定大于配置,那么很有必要对在开发过程中这些配置做统一的添加记录,以免用到的时候到处搜索,网上的东西又良莠不齐。
server.port=8880
微服务注册中心,yml文件
server: port: 8761 # 服务在启动时,会把自己当做一个 Eureka 客户端去注册到 Eureka 服务器上,且从服务器上拉取信息 # 而该服务本身就是一个 Eureka 服务器 eureka: client: # 声明是否将自己的信息注册到 Eureka 服务器上 register-with-eureka: false # 是否到 Eureka 服务器中抓取注册信息 fetch-registry: false service-url: defaultZone: http://localhost:8761/eureka instance: hostname: localhost # 心跳检测检测与续约时间 # 测试时将值设置设置小些,保证服务关闭后注册中心能及时踢出服务 # 每间隔1s,向服务端发送一次心跳,证明自己依然”存活“ lease-renewal-interval-in-seconds: 1 # 告诉服务端,如果我2s之内没有给你发心跳,就代表我“死”了,将我踢出掉。 lease-expiration-duration-in-seconds: 2 server: # 测试时关闭自我保护机制,保证不可用服务及时踢出 无法出现RENEWALS ARE LESSER THAN THE THRESHOLD. THE SELF PRESERVATION MODE IS TURNED OFF.THIS MAY NOT PROTECT INSTANCE EXPIRY IN CASE OF NETWORK/OTHER PROBLEMS. enable-self-preservation: true spring: application: name:master #启用shutdown endpoints: shutdown: enabled : true # 禁用密码验证 sensitive : false
数据库,mysql
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://test:3306/sy?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE&zeroDateTimeBehavior=convertToNull spring.datasource.username=test spring.datasource.password=test
rabbitmq
spring.rabbitmq.host=test spring.rabbitmq.port=5672 spring.rabbitmq.username=test spring.rabbitmq.password=test spring.rabbitmq.publisher-confirms=true spring.rabbitmq.virtual-host=/
静态文件
spring.resources.static-locations = classpath:/templates/,classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
security
security.user.name=admin security.user.password=123456 security.basic.path=/manage management.security.role=SUPERUSER
endpoints方式停止
endpoints.shutdown.enabled=true endpoints.shutdown.sensitive=true
文件上传限制
spring.http.multipart.maxFileSize=10MB
spring.http.multipart.maxRequestSize=50MB
统一添加url地址,在微服务中特别有用
server.context-path=/admin
redis
spring.redis.host = localhost spring.redis.port = 6379 spring.redis.timeout = 10000 spring.redis.database = 0 spring.redis.pool.max-active = 100 spring.redis.pool.max-wait = -1 spring.redis.pool.max-idle = 8 spring.redis.pool.min-idle = 0
elasticsearch
elasticsearch.ip=test elasticsearch.port=9300 elasticsearch.cluster.name=my-elasticsearch elasticsearch.pool=100 elasticsearch.index=visual elasticsearch.type=plate-pictrue
fastdfs
fastdfs.minPoolSize=10 fastdfs.maxPoolSize=30 fastdfs.waitTimes=200 connect_timeout = 2 network_timeout = 30 charset = UTF-8 http.tracker_http_port = 8180 tracker_server = localhost:22122
时间格式化,全局配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
如果代码中需要用到日期那在代码中
@JsonFormat(pattern = "yyyy-MM-dd") private Date brithday;
微服务
#微服务注册中心 eureka.client.serviceUrl.defaultZone=http://test:8761/eureka/ #微服务应用名称 spring.application.name=sy-admin #微服务名称,通过此名称来访问 spring.service.name=sy-admin #微服务实例地址 eureka.instance.hostname=localhost
苍茫之天涯,乃吾辈之所爱也;浩瀚之程序,亦吾之所爱也,然则何时而爱耶?必曰:先天下之忧而忧,后天下之爱而爱也!