spring boot 1.x配置,不斷完善中
阿新 • • 發佈:2018-11-20
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