1. 程式人生 > >Spring Boot環境的搭建

Spring Boot環境的搭建

什麼是Spring Boot?

Spring Boot是由Pivotal團隊提供的全新框架,其設計目的是用來簡化新Spring應用的初始搭建以及開發過程。該框架使用了特定的方式來進行配置,從而使開發人員不再需要定義樣板化的配置。

自己的理解就是spring boot其實不是什麼新的框架,它只是預設配置了很多框架的使用方式,就像maven整合了所有的jar包,spring boot整合了所有的框架,需要哪個框架的時候,只需要新建專案的時候勾選相應的框架核心,然後不需要引入額外的Jar包,因為spring boot幫我們做了這件事。

spring boot的特點

  • 建立獨立的Spring應用程式
  • 嵌入的Tomcat,無需部署WAR檔案,能直接執行程式
  • 簡化Maven配置,不需要在pom.xml檔案引入過多的jar包
  • 自動配置Spring,不需要新建spring的核心配置檔案
  • 提供生產就緒型功能,如指標,健康檢查和外部配置
  • 絕對沒有程式碼生成並且對XML也沒有配置要求

spring boot的優點

使用spring boot搭建專案,其突出優點就是簡單、快速、方便!
平時搭建一個spring web專案的時候可能需要以下步驟:

1.配置web.xml,載入spring核心配置檔案和spring mvc的配置檔案
2.配置資料庫連線、配置spring事務
3.配置載入配置檔案的讀取,開啟註解
4.配置日誌檔案

配置完成之後部署tomcat 除錯

等一系列操作,可能一不小心就漏了哪個步驟,又得重新檢查一遍。。。
而spring boot可以幫你解決傳統的spring web專案構建的繁瑣步驟,一步到位。
說了這麼多,接下來一起來學習怎樣使用吧。(它可以應用在快速搭建web專案和為服務)

搭建一個簡單的Spring Boot

  1. 新建一個全新的project
    springboot2.0以上的版本,jdkz最好選擇jdk1.8以上在這裡插入圖片描述

在這裡插入圖片描述
在這裡插入圖片描述
在這裡插入圖片描述
因為需要訪問其官網下載初始化的程式,映象在國外,所以初始化第一個project的時候很慢,以後在此project新建Model就不用載入如此慢。
在這裡插入圖片描述


2.看一下新建的spring boot的project
在這裡插入圖片描述
3.測試能否不配置繁瑣的spring的各種配置檔案,能否訪問成功
1)在這裡插入圖片描述
在此目錄下新建controller包,包下新建TestController.java

package com.springboot.springboot.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 小思
 * @PackageName:com.springboot.springboot.controller
 * @ClassName: TestController
 * @Description:測試spring boot訪問控制器
 * @date 2018/11/18 20:07
 */
@Controller
public class TestController {
    @RequestMapping("/hello")
    public String sayHello(){
        System.out.println("hello spring boot");
        return "index";
    }
}

2)啟動伺服器,執行專案
在這裡插入圖片描述
在這裡插入圖片描述
環境搭建成功!

在這裡插入圖片描述

下面是博主蒐集的常用的application.properties配置資訊

蒐集地址:https://blog.csdn.net/je_ge/article/details/54783184

SPRING CONFIG (ConfigFileApplicationListener)

spring.config.name
配置檔名稱,預設為application
spring.config.location
配置檔案存放位置,預設為classpath目錄下

mvc

spring.mvc.async.request-timeout
設定async請求的超時時間,以毫秒為單位,如果沒有設定的話,以具體實現的超時時間為準,比如tomcat的servlet3的話是10秒.
spring.mvc.date-format
設定日期的格式,比如dd/MM/yyyy.
spring.mvc.favicon.enabled
是否支援favicon.ico,預設為: true
spring.mvc.ignore-default-model-on-redirect
在重定向時是否忽略預設model的內容,預設為true
spring.mvc.locale
指定使用的Locale.
spring.mvc.message-codes-resolver-format
指定message codes的格式化策略(PREFIX_ERROR_CODE,POSTFIX_ERROR_CODE).
spring.mvc.view.prefix
指定mvc檢視的字首.
spring.mvc.view.suffix
指定mvc檢視的字尾.

messages

spring.messages.basename
指定message的basename,多個以逗號分隔,如果不加包名的話,預設從classpath路徑開始,預設: messages
spring.messages.cache-seconds
設定載入的資原始檔快取失效時間,-1的話為永不過期,預設為-1
spring.messages.encoding
設定Message bundles的編碼,預設: UTF-8

mobile

spring.mobile.devicedelegatingviewresolver.enable-fallback
是否支援fallback的解決方案,預設false
spring.mobile.devicedelegatingviewresolver.enabled
是否開始device view resolver,預設為: false
spring.mobile.devicedelegatingviewresolver.mobile-prefix
設定mobile端檢視的字首,預設為:mobile/
spring.mobile.devicedelegatingviewresolver.mobile-suffix
設定mobile檢視的字尾
spring.mobile.devicedelegatingviewresolver.normal-prefix
設定普通裝置的檢視字首
spring.mobile.devicedelegatingviewresolver.normal-suffix
設定普通裝置檢視的字尾
spring.mobile.devicedelegatingviewresolver.tablet-prefix
設定平板裝置檢視字首,預設:tablet/
spring.mobile.devicedelegatingviewresolver.tablet-suffix
設定平板裝置檢視字尾.
spring.mobile.sitepreference.enabled
是否啟用SitePreferenceHandler,預設為: true

view

spring.view.prefix
設定mvc檢視的字首.
spring.view.suffix
設定mvc檢視的字尾.

resource

spring.resources.add-mappings
是否開啟預設的資源處理,預設為true
spring.resources.cache-period
設定資源的快取時效,以秒為單位.
spring.resources.chain.cache
是否開啟快取,預設為: true
spring.resources.chain.enabled
是否開啟資源 handling chain,預設為false
spring.resources.chain.html-application-cache
是否開啟h5應用的cache manifest重寫,預設為: false
spring.resources.chain.strategy.content.enabled
是否開啟內容版本策略,預設為false
spring.resources.chain.strategy.content.paths
指定要應用的版本的路徑,多個以逗號分隔,預設為:[/**]
spring.resources.chain.strategy.fixed.enabled
是否開啟固定的版本策略,預設為false
spring.resources.chain.strategy.fixed.paths
指定要應用版本策略的路徑,多個以逗號分隔
spring.resources.chain.strategy.fixed.version
指定版本策略使用的版本號
spring.resources.static-locations
指定靜態資源路徑,預設為classpath:[/META-INF/resources/,/resources/, /static/, /public/]以及context:/

multipart

multipart.enabled
是否開啟檔案上傳支援,預設為true
multipart.file-size-threshold
設定檔案寫入磁碟的閾值,單位為MB或KB,預設為0
multipart.location
指定檔案上傳路徑.
multipart.max-file-size
指定檔案大小最大值,預設1MB
multipart.max-request-size
指定每次請求的最大值,預設為10MB

freemarker

spring.freemarker.allow-request-override
指定HttpServletRequest的屬性是否可以覆蓋controller的model的同名項
spring.freemarker.allow-session-override
指定HttpSession的屬性是否可以覆蓋controller的model的同名項
spring.freemarker.cache
是否開啟template caching.
spring.freemarker.charset
設定Template的編碼.
spring.freemarker.check-template-location
是否檢查templates路徑是否存在.
spring.freemarker.content-type
設定Content-Type.
spring.freemarker.enabled
是否允許mvc使用freemarker.
spring.freemarker.expose-request-attributes
設定所有request的屬性在merge到模板的時候,是否要都新增到model中.
spring.freemarker.expose-session-attributes
設定所有HttpSession的屬性在merge到模板的時候,是否要都新增到model中.
spring.freemarker.expose-spring-macro-helpers
設定是否以springMacroRequestContext的形式暴露RequestContext給Spring’s macro library使用
spring.freemarker.prefer-file-system-access
是否優先從檔案系統載入template,以支援熱載入,預設為true
spring.freemarker.prefix
設定freemarker模板的字首.
spring.freemarker.request-context-attribute
指定RequestContext屬性的名.
spring.freemarker.settings
設定FreeMarker keys.
spring.freemarker.suffix
設定模板的字尾.
spring.freemarker.template-loader-path
設定模板的載入路徑,多個以逗號分隔,預設: [“classpath:/templates/”]
spring.freemarker.view-names
指定使用模板的檢視列表.

velocity

spring.velocity.allow-request-override
指定HttpServletRequest的屬性是否可以覆蓋controller的model的同名項
spring.velocity.allow-session-override
指定HttpSession的屬性是否可以覆蓋controller的model的同名項
spring.velocity.cache
是否開啟模板快取
spring.velocity.charset
設定模板編碼
spring.velocity.check-template-location
是否檢查模板路徑是否存在.
spring.velocity.content-type
設定ContentType的值
spring.velocity.date-tool-attribute
設定暴露給velocity上下文使用的DateTool的名
spring.velocity.enabled
設定是否允許mvc使用velocity
spring.velocity.expose-request-attributes
是否在merge模板的時候,將request屬性都新增到model中
spring.velocity.expose-session-attributes
是否在merge模板的時候,將HttpSession屬性都新增到model中
spring.velocity.expose-spring-macro-helpers
設定是否以springMacroRequestContext的名來暴露RequestContext給Spring’s macro類庫使用
spring.velocity.number-tool-attribute
設定暴露給velocity上下文的NumberTool的名
spring.velocity.prefer-file-system-access
是否優先從檔案系統載入模板以支援熱載入,預設為true
spring.velocity.prefix
設定velocity模板的字首.
spring.velocity.properties
設定velocity的額外屬性.
spring.velocity.request-context-attribute
設定RequestContext attribute的名.
spring.velocity.resource-loader-path
設定模板路徑,預設為: classpath:/templates/
spring.velocity.suffix
設定velocity模板的字尾.
spring.velocity.toolbox-config-location
設定Velocity Toolbox配置檔案的路徑,比如 /WEB-INF/toolbox.xml.
spring.velocity.view-names
設定需要解析的檢視名稱.

thymeleaf

spring.thymeleaf.cache
是否開啟模板快取,預設true
spring.thymeleaf.check-template-location
是否檢查模板路徑是否存在,預設true
spring.thymeleaf.content-type
指定Content-Type,預設為: text/html
spring.thymeleaf.enabled
是否允許MVC使用Thymeleaf,預設為: true
spring.thymeleaf.encoding
指定模板的編碼,預設為: UTF-8
spring.thymeleaf.excluded-view-names
指定不使用模板的檢視名稱,多個以逗號分隔.
spring.thymeleaf.mode
指定模板的模式,具體檢視StandardTemplateModeHandlers,預設為: HTML5
spring.thymeleaf.prefix
指定模板的字首,預設為:classpath:/templates/
spring.thymeleaf.suffix
指定模板的字尾,預設為:.html
spring.thymeleaf.template-resolver-order
指定模板的解析順序,預設為第一個.
spring.thymeleaf.view-names
指定使用模板的檢視名,多個以逗號分隔.

mustcache

spring.mustache.cache
是否Enable template caching.
spring.mustache.charset
指定Template的編碼.
spring.mustache.check-template-location
是否檢查預設的路徑是否存在.
spring.mustache.content-type
指定Content-Type.
spring.mustache.enabled
是否開啟mustcache的模板支援.
spring.mustache.prefix
指定模板的字首,預設: classpath:/templates/
spring.mustache.suffix
指定模板的字尾,預設: .html
spring.mustache.view-names
指定要使用模板的檢視名.

groovy模板

spring.groovy.template.allow-request-override
指定HttpServletRequest的屬性是否可以覆蓋controller的model的同名項
spring.groovy.template.allow-session-override
指定HttpSession的屬性是否可以覆蓋controller的model的同名項
spring.groovy.template.cache
是否開啟模板快取.
spring.groovy.template.charset
指定Template編碼.
spring.groovy.template.check-template-location
是否檢查模板的路徑是否存在.
spring.groovy.template.configuration.auto-escape
是否在渲染模板時自動排查model的變數,預設為: false
spring.groovy.template.configuration.auto-indent
是否在渲染模板時自動縮排,預設為false
spring.groovy.template.configuration.auto-indent-string
如果自動縮排啟用的話,是使用SPACES還是TAB,預設為: SPACES
spring.groovy.template.configuration.auto-new-line
渲染模板時是否要輸出換行,預設為false
spring.groovy.template.configuration.base-template-class
指定template base class.
spring.groovy.template.configuration.cache-templates
是否要快取模板,預設為true
spring.groovy.template.configuration.declaration-encoding
在寫入declaration header時使用的編碼
spring.groovy.template.configuration.expand-empty-elements
是使用
這種形式,還是
這種展開模式,預設為: false)
spring.groovy.template.configuration.locale
指定template locale.
spring.groovy.template.configuration.new-line-string
當啟用自動換行時,換行的輸出,預設為系統的line.separator屬性的值
spring.groovy.template.configuration.resource-loader-path
指定groovy的模板路徑,預設為classpath:/templates/
spring.groovy.template.configuration.use-double-quotes
指定屬性要使用雙引號還是單引號,預設為false
spring.groovy.template.content-type
指定Content-Type.
spring.groovy.template.enabled
是否開啟groovy模板的支援.
spring.groovy.template.expose-request-attributes
設定所有request的屬性在merge到模板的時候,是否要都新增到model中.
spring.groovy.template.expose-session-attributes
設定所有request的屬性在merge到模板的時候,是否要都新增到model中.
spring.groovy.template.expose-spring-macro-helpers
設定是否以springMacroRequestContext的形式暴露RequestContext給Spring’s macro library使用
spring.groovy.template.prefix
指定模板的字首.
spring.groovy.template.request-context-attribute
指定RequestContext屬性的名.
spring.groovy.template.resource-loader-path
指定模板的路徑,預設為: classpath:/templates/
spring.groovy.template.suffix
指定模板的字尾
spring.groovy.template.view-names
指定要使用模板的檢視名稱.

http

spring.hateoas.apply-to-primary-object-mapper
設定是否對object mapper也支援HATEOAS,預設為: true
spring.http.converters.preferred-json-mapper
是否優先使用JSON mapper來轉換.
spring.http.encoding.charset
指定http請求和相應的Charset,預設: UTF-8
spring.http.encoding.enabled
是否開啟http的編碼支援,預設為true
spring.http.encoding.force
是否強制對http請求和響應進行編碼,預設為true

json

spring.jackson.date-format
指定日期格式,比如yyyy-MM-dd HH:mm:ss,或者具體的格式化類的全限定名
spring.jackson.deserialization
是否開啟Jackson的反序列化
spring.jackson.generator
是否開啟json的generators.
spring.jackson.joda-date-time-format
指定Joda date/time的格式,比如yyyy-MM-dd HH:mm:ss). 如果沒有配置的話,dateformat會作為backup
spring.jackson.locale
指定json使用的Locale.
spring.jackson.mapper
是否開啟Jackson通用的特性.
spring.jackson.parser
是否開啟jackson的parser特性.
spring.jackson.property-naming-strategy
指定PropertyNamingStrategy (CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES)或者指定PropertyNamingStrategy子類的全限定類名.
spring.jackson.serialization
是否開啟jackson的序列化.
spring.jackson.serialization-inclusion
指定序列化時屬性的inclusion方式,具體檢視JsonInclude.Include列舉.
spring.jackson.time-zone
指定日期格式化時區,比如America/Los_Angeles或者GMT+10.

jersey

spring.jersey.filter.order
指定Jersey filter的order,預設為: 0
spring.jersey.init
指定傳遞給Jersey的初始化引數.
spring.jersey.type
指定Jersey的整合型別,可以是servlet或者filter.

PROFILES

spring.profiles.active= # comma list of active profiles
spring.profiles.include= # unconditionally activate the specified comma separated profiles

APPLICATION SETTINGS (SpringApplication)

spring.main.sources=
spring.main.web-environment= # detect by default
spring.main.show-banner=true
spring.main….= # see class for all properties

LOGGING

logging.path=/var/logs
logging.file=myapp.log
logging.config= # location of config file (default classpath:logback.xml for logback)
logging.level.*= # levels for loggers, e.g. “logging.level.org.springframework=DEBUG” (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)

IDENTITY (ContextIdApplicationContextInitializer)

spring.application.name=
spring.application.index=

EMBEDDED SERVER CONFIGURATION (ServerProperties)

server.port=8080
server.address= # bind to a specific NIC
server.session-timeout= # session timeout in seconds
server.context-parameters.*= # Servlet context init parameters, e.g. server.context-parameters.a=alpha
server.context-path= # the context path, defaults to ‘/’
server.servlet-path= # the servlet path, defaults to ‘/’
server.ssl.enabled=true # if SSL support is enabled
server.ssl.client-auth= # want or need
server.ssl.key-alias=
server.ssl.ciphers= # supported SSL ciphers
server.ssl.key-password=
server.ssl.key-store=
server.ssl.key-store-password=
server.ssl.key-store-provider=
server.ssl.key-store-type=
server.ssl.protocol=TLS
server.ssl.trust-store=
server.ssl.trust-store-password=
server.ssl.trust-store-provider=
server.ssl.trust-store-type=
server.tomcat.access-log-pattern= # log pattern of the access log
server.tomcat.access-log-enabled=false # is access logging enabled
server.tomcat.internal-proxies=10.\d{1,3}.\d{1,3}.\d{1,3}|\
192.168.\d{1,3}.\d{1,3}|\
169.254.\d{1,3}.\d{1,3}|\
127.\d{1,3}.\d{1,3}.\d{1,3} # regular expression matching trusted IP addresses
server.tomcat.protocol-header=x-forwarded-proto # front end proxy forward header
server.tomcat.port-header= # front end proxy port header
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)
server.tomcat.background-processor-delay=30; # in seconds
server.tomcat.max-http-header-size= # maximum size in bytes of the HTTP message header
server.tomcat.max-threads = 0 # number of threads in protocol handler
server.tomcat.uri-encoding = UTF-8 # character encoding to use for URL decoding

SPRING MVC (WebMvcProperties)

spring.mvc.locale= # set fixed locale, e.g. en_UK
spring.mvc.date-format= # set fixed date format, e.g. dd/MM/yyyy
spring.mvc.message-codes-resolver-format= # PREFIX_ERROR_CODE / POSTFIX_ERROR_CODE
spring.mvc.ignore-default-model-on-redirect=true # If the the content of the “default” model should be ignored redirects
spring.view.prefix= # MVC view prefix
spring.view.suffix= # … and suffix
spring.resources.cache-period= # cache timeouts in headers sent to browser
spring.resources.add-mappings=true # if default mappings should be added

SPRING HATEOS (HateoasProperties)

spring.hateoas.apply-to-primary-object-mapper=true # if the primary mapper should also be configured

HTTP encoding (HttpEncodingProperties)

spring.http.encoding.charset=UTF-8 # the encoding of HTTP requests/responses
spring.http.encoding.enabled=true # enable http encoding support
spring.http.encoding.force=true # force the configured encoding

JACKSON (JacksonProperties)

spring.jackson.date-format= # Date format string (e.g. yyyy-MM-dd HH:mm:ss), or a fully-qualified date format class name (e.g. com.fasterxml.jackson.databind.util.ISO8601DateFormat)
spring.jackson.property-naming-strategy= # One of the constants on Jackson’s PropertyNamingStrategy (e.g. CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES) or the fully-qualified class name of a PropertyNamingStrategy subclass
spring.jackson.deserialization.= # see Jackson’s DeserializationFeature
spring.jackson.generator.
= # see Jackson’s JsonGenerator.Feature
spring.jackson.mapper.= # see Jackson’s MapperFeature
spring.jackson.parser.
= # see Jackson’s JsonParser.Feature
spring.jackson.serialization.*= # see Jackson’s SerializationFeature

THYMELEAF (ThymeleafAutoConfiguration)

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.excluded-view-names= # comma-separated list of view names that should be excluded from resolution
spring.thymeleaf.view-names= # comma-separated list of view names that can be resolved
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html # ;charset= is added
spring.thymeleaf.cache=true # set to false for hot refresh

REEMARKER (FreeMarkerAutoConfiguration)

spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
spring.freemarker.prefix=
spring.freemarker.request-context-attribute=
spring.freemarker.settings.*=
spring.freemarker.suffix=.ftl
spring.freemarker.template-loader-path=classpath:/templates/ # comma-separated list
spring.freemarker.view-names= # whitelist of view names that can be resolved

GROOVY TEMPLATES (GroovyTemplateAutoConfiguration)

spring.groovy.template.cache=true
spring.groovy.template.charset=UTF-8
spring.groovy.template.configuration.*= # See Groovy’s TemplateConfiguration
spring.groovy.template.content-type=text/html
spring.groovy.template.prefix=classpath:/templates/
spring.groovy.template.suffix=.tpl
spring.groovy.template.view-names= # whitelist of view names that can be resolved

VELOCITY TEMPLATES (VelocityAutoConfiguration)

spring.velocity.allow-request-override=false
spring.velocity.cache=true
spring.velocity.check-template-location=true
spring.velocity.charset=UTF-8
spring.velocity.content-type=text/html
spring.velocity.date-tool-attribute=
spring.velocity.expose-request-attributes=false
spring.velocity.expose-session-attributes=false
spring.velocity.expose-spring-macro-helpers=false
spring.velocity.number-tool-attribute=
spring.velocity.prefer-file-system-access=true # prefer file system access for template loading
spring.velocity.prefix=
spring.velocity.properties.*=
spring.velocity.request-context-attribute=
spring.velocity.resource-loader-path=classpath:/templates/
spring.velocity.suffix=.vm
spring.velocity.toolbox-config-location= # velocity Toolbox config location, for example “/WEB-INF/toolbox.xml”
spring.velocity.view-names= # whitelist of view names that can be resolved

JERSEY (JerseyProperties)

spring.jersey.type=servlet # servlet or filter
spring.jersey.init= # init params
spring.jersey.filter.order=

INTERNATIONALIZATION (MessageSourceAutoConfiguration)

spring.messages.basename=messages
spring.messages.cache-seconds=-1
spring.messages.encoding=UTF-8

SECURITY (SecurityProperties)

security.user.name=user # login username
security.user.password= # login password
security.user.role=USER # role assigned to the user
security.require-ssl=false # advanced settings …
security.enable-csrf=false
security.basic.enabled=true
security.basic.realm=Spring
security.basic.path= # /**
security.filter-order=0
security.headers.xss=false
security.headers.cache=false
security.headers.frame=false
security.headers.content-type=false
security.headers.hsts=all # none / domain / all
security.sessions=stateless # always / never / if_required / stateless
security.ignored=false

DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)

spring.datasource.name= # name of the data source
spring.datasource.initialize=true # populate using data.sql
spring.datasource.schema= # a schema (DDL) script resource reference
spring.datasource.data= # a data (DML) script resource reference
spring.datasource.sql-script-encoding= # a charset for reading SQL scripts
spring.datasource.platform= # the platform to use in the schema resource (schema-KaTeX parse error: Expected 'EOF', got '#' at position 61: …on-error=false #̲ continue even …{platform}.sql),預設為: all
spring.datasource.pool-name
指定連線池名字.
spring.datasource.pool-prepared-statements
指定是否池化statements.
spring.datasource.propagate-interrupt-state
在等待連線時,如果執行緒被中斷,是否傳播中斷狀態.
spring.datasource.read-only
當使用Hikari connection pool時,是否標記資料來源只讀
spring.datasource.register-mbeans
指定Hikari connection pool是否註冊JMX MBeans.
spring.datasource.remove-abandoned
指定當連線超過廢棄超時時間時,是否立刻刪除該連線.
spring.datasource.remove-abandoned-timeout
指定連線應該被廢棄的時間.
spring.datasource.rollback-on-return
在歸還連線時,是否回滾等待中的事務.
spring.datasource.schema
指定Schema (DDL)指令碼.
spring.datasource.separator
指定初始化指令碼的語句分隔符,預設: ;
spring.datasource.sql-script-encoding
指定SQL scripts編碼.
spring.datasource.suspect-timeout
指定列印廢棄連線前的超時時間.
spring.datasource.test-on-borrow
當從連線池借用連線時,是否測試該連線.
spring.datasource.test-on-connect
建立時,是否測試連線
spring.datasource.test-on-return
在連線歸還到連線池時是否測試該連線.
spring.datasource.test-while-idle
當連線空閒時,是否執行連線測試.
spring.datasource.time-between-eviction-runs-millis
指定空閒連線檢查、廢棄連線清理、空閒連線池大小調整之間的操作時間間隔
spring.datasource.transaction-isolation
指定事務隔離級別,使用Hikari connection pool時指定
spring.datasource.url
指定JDBC URL.
spring.datasource.use-disposable-connection-facade
是否對連線進行包裝,防止連線關閉之後被使用.
spring.datasource.use-equals
比較方法名時是否使用String.equals()替換==.
spring.datasource.use-lock
是否對連線操作加鎖
spring.datasource.username
指定資料庫名.
spring.datasource.validation-interval
指定多少ms執行一次連線校驗.
spring.datasource.validation-query
指定獲取連線時連線校驗的sql查詢語句.
spring.datasource.validation-query-timeout
指定連線校驗查詢的超時時間.
spring.datasource.validation-timeout
設定連線校驗的超時時間,當使用Hikari connection pool時指定
spring.datasource.validator-class-name
用來測試查詢的validator全限定名.
spring.datasource.xa.data-source-class-name
指定資料來源的全限定名.
spring.datasource.xa.properties
指定傳遞給XA data source的屬性
spring.datasource.name= # name of the data source
spring.datasource.initialize=true # populate using data.sql
spring.datasource.schema= # a schema (DDL) script resource reference
spring.datasource.data= # a data (DML) script resource reference
spring.datasource.sql-script-encoding= # a charset for reading SQL scripts
spring.datasource.platform= # the platform to use in the schema resource (schema-KaTeX parse error: Expected 'EOF', got '#' at position 61: …on-error=false #̲ continue even …{platform}.sql),預設為: all
spring.datasource.pool-name
指定連線池名字.
spring.datasource.pool-prepared-statements
指定是否池化statements.
spring.datasource.propagate-interrupt-state
在等待連線時,如果執行緒被中斷,是否傳播中斷狀態.
spring.datasource.read-only
當使用Hikari connection pool時,是否標記資料來源只讀
spring.datasource.register-mbeans
指定Hikari connection pool是否註冊JMX MBeans.
spring.datasource.remove-abandoned
指定當連線超過廢棄超時時間時,是否立刻刪除該連線.
spring.datasource.remove-abandoned-timeout
指定連線應該被廢棄的時間.
spring.datasource.rollback-on-return
在歸還連線時,是否回滾等待中的事務.
spring.datasource.schema
指定Schema (DDL)指令碼.
spring.datasource.separator
指定初始化指令碼的語句分隔符,預設: ;
spring.datasource.sql-script-encoding
指定SQL scripts編碼.
spring.datasource.suspect-timeout
指定列印廢棄連線前的超時時間.
spring.datasource.test-on-borrow
當從連線池借用連線時,是否測試該連線.
spring.datasource.test-on-connect
建立時,是否測試連線
spring.datasource.test-on-return
在連線歸還到連線池時是否測試該連線.
spring.datasource.test-while-idle
當連線空閒時,是否執行連線測試.
spring.datasource.time-between-eviction-runs-millis
指定空閒連線檢查、廢棄連線清理、空閒連線池大小調整之間的操作時間間隔
spring.datasource.transaction-isolation
指定事務隔離級別,使用Hikari connection pool時指定
spring.datasource.url
指定JDBC URL.
spring.datasource.use-disposable-connection-facade
是否對連線進行包裝,防止連線關閉之後被使用.
spring.datasource.use-equals
比較方法名時是否使用String.equals()替換==.
spring.datasource.use-lock
是否對連線操作加鎖
spring.datasource.username
指定資料庫名.
spring.datasource.validation-interval
指定多少ms執行一次連線校驗.
spring.datasource.validation-query
指定獲取連線時連線校驗的sql查詢語句.
spring.datasource.validation-query-timeout
指定連線校驗查詢的超時時間.
spring.datasource.validation-timeout
設定連線校驗的超時時間,當使用Hikari connection pool時指定
spring.datasource.validator-class-name
用來測試查詢的validator全限定名.
spring.datasource.xa.data-source-class-name
指定資料來源的全限定名.
spring.datasource.xa.properties
指定傳遞給XA data source的屬性

DATASOURCE (PersistenceExceptionTranslationAutoConfiguration

spring.dao.exceptiontranslation.enabled=true

MONGODB (MongoProperties)

spring.data.mongodb.host= # the db host
spring.data.mongodb.port=27017 # the connection port (defaults to 27107)
spring.data.mongodb.uri=mongodb://localhost/test # connection URL
spring.data.mongodb.database=
spring.data.mongodb.authentication-database=
spring.data.mongodb.grid-fs-database=
spring.data.mongodb.username=
spring.data.mongodb.password=
spring.data.mongodb.repositories.enabled=true # if spring data repository support is enabled

JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)

spring.jpa.properties.*= # properties to set on the JPA connection
spring.jpa.open-in-view=true
spring.jpa.show-sql=true
spring.jpa.database-platform=
spring.jpa.database=
spring.jpa.generate-ddl=false # ignored by Hibernate, might be useful for other vendors
spring.jpa.hibernate.naming-strategy= # naming classname
spring.jpa.hibernate.ddl-auto= # defaults to create-drop for embedded dbs
spring.data.jpa.repositories.enabled=true # if spring data repository support is enabled

JTA (JtaAutoConfiguration)

spring.jta.log-dir= # transaction log dir
spring.jta.*= # technology specific configuration

SOLR (SolrProperties})

spring.data.solr.host=http://127.0.0.1:8983/solr
spring.data.solr.zk-host=
spring.data.solr.repositories.enabled=true # if spring data repository support is enabled

ELASTICSEARCH (ElasticsearchProperties})

spring.data.elasticsearch.cluster-name= # The cluster name (defaults to elasticsearch)
spring.data.elasticsearch.cluster-nodes= # The address(es) of the server node (comma-separated; if not specified starts a client node)
spring.data.elasticsearch.repositories.enabled=true # if spring data repository support is enabled

DATA RESET (RepositoryRestConfiguration})

spring.data.rest.base-uri= # base URI against which the exporter should calculate its links

FLYWAY (FlywayProperties)

flyway.check-location=false # check that migration scripts location exists
flyway.locations=classpath:db/migration # locations of migrations scripts
flyway.schemas= # schemas to update
flyway.init-version= 1 # version to start migration
flyway.init-sqls= # SQL statements to execute to initialize a connection immediately after obtaining it
flyway.sql-migration-prefix=V
flyway.sql-migration-suffix=.sql
flyway.enabled=true
flyway.url= # JDBC url if you want Flyway to create its own DataSource
flyway.user= # JDBC username if you want Flyway to create its own DataSource
flyway.password= # JDBC password if you want Flyway to create its own DataSource

LIQUIBASE (LiquibaseProperties)

liquibase.change-log=classpath:/db/changelog/db.changelog-master.yaml
liquibase.check-change-log-location=true # check the change log location exists
liquibase.contexts= # runtime contexts to use
liquibase.default-schema= # default database schema to use
liquibase.drop-first=false
liquibase.enabled=true
liquibase.url= # specific JDBC url (if not set the default datasource is used)
liquibase.user= # user name for liquibase.url
liquibase.password= # password for liquibase.url

JMX

spring.jmx.enabled=true # Expose MBeans from Spring

RABBIT (RabbitProperties)

spring.rabbitmq.host= # connection host
spring.rabbitmq.port= # connection port
spring.rabbitmq.addresses= # connection addresses (e.g. myhost:9999,otherhost:1111)
spring.rabbitmq.username= # login user
spring.rabbitmq.password= # login password
spring.rabbitmq.virtual-host=
spring.rabbitmq.dynamic=

REDIS (RedisProperties)

spring.redis.database= # database name
spring.redis.host=localhost # server host
spring.redis.password= # server password
spring.redis.port=6379 # connection port
spring.redis.pool.max-idle=8 # pool settings …
spring.redis.pool.min-idle=0
spring.redis.pool.max-active=8
spring.redis.pool.max-wait=-1
spring.redis.sentinel.master= # name of Redis server
spring.redis.sentinel.nodes= # comma-separated list of host:port pairs
Redis資料庫索引(預設為0)

  • spring.redis.database=0
    Redis伺服器地址
  • spring.redis.host=192.168.0.58
    Redis伺服器連線埠
  • spring.redis.port=6379
  • Redis伺服器連線密碼(預設為空)
  • spring.redis.password=
    連線池最大連線數(使用負值表示沒有限制)
  • spring.redis.pool.max-active=8
    連線池最大阻塞等待時間(使用負值表示沒有限制)
  • spring.redis.pool.max-wait=-1
    連線池中的最大空閒連線
  • spring.redis.pool.max-idle=8
    連線池中的最小空閒連線
  • spring.redis.pool.min-idle=0
    連線超時時間(毫秒)
  • spring.redis.timeout=0

ACTIVEMQ (ActiveMQProperties)

spring.activemq.broker-url=tcp://localhost:61616 # connection URL
spring.activemq.user=
spring.activemq.password=
spring.activemq.in-memory=true # broker kind to create if no broker-url is specified
spring.activemq.pooled=false

HornetQ (HornetQProperties)

spring.hornetq.mode= # connection mode (native, embedded)
spring.hornetq.host=localhost # hornetQ host (native mode)
spring.hornetq.port=5445 # hornetQ port (native mode)
spring.hornetq.embedded.enabled=true # if the embedded server is enabled (needs hornetq-jms-server.jar)
spring.hornetq.embedded.server-id= # auto-generated id of the embedded server (integer)
spring.hornetq.embedded.persistent=false # message persistence
spring.hornetq.embedded.data-directory= # location of data content (when persistence is enabled)
spring.hornetq.embedded.queues= # comma-separated queues to create on startup
spring.hornetq.embedded.topics= # comma-separated topics to create on startup
spring.hornetq.embedded.cluster-password= # customer password (randomly generated by default)

JMS (JmsProperties)

spring.jms.jndi-name= # JNDI location of a JMS ConnectionFactory
spring.jms.pub-sub-domain= # false for queue (default), true for topic

Email (MailProperties)

spring.mail.host=smtp.acme.org # mail server host
spring.mail.port= # mail server port
spring.mail.username=
spring.mail.password=
spring.mail.default-encoding=UTF-8 # encoding to use for MimeMessages
spring.mail.properties.*= # properties to set on the JavaMail session

SPRING BATCH (BatchDatabaseInitializer)

spring.batch.job.names=job1,job2
spring.batch.job.enabled=true
spring.batch.initializer.enabled=true
spring.batch.schema= # batch schema to load

AOP

spring.aop.auto=
spring.aop.proxy-target-class=

FILE ENCODING (FileEncodingApplicationListener)

spring.mandatory-file-encoding=false

SPRING SOCIAL (SocialWebAutoConfiguration)

spring.social.auto-connection-views=true # Set to true for default connection views or false if you provide your own

SPRING SOCIAL FACEBOOK (FacebookAutoConfiguration)

spring.social.facebook.app-id= # your application’s Facebook App ID
spring.social.facebook.app-secret= # your application’s Facebook App Secret

SPRING SOCIAL LINKEDIN (LinkedInAutoConfiguration)
spring.social.linkedin.app-id= # your application’s LinkedIn App ID
spring.social.linkedin.app-secret= # your application’s LinkedIn App Secret

SPRING SOCIAL TWITTER (TwitterAutoConfiguration)

spring.social.twitter.app-id= # your application’s Twitter App ID
spring.social.twitter.app-secret= # your application’s Twitter App Secret

SPRING MOBILE SITE PREFERENCE (SitePreferenceAutoConfiguration)

spring.mobile.sitepreference.enabled=true # enabled by default

SPRING MOBILE DEVICE VIEWS (DeviceDelegatingViewResolverAutoConfiguration)

spring.mobile.devicedelegatingviewresolver.enabled=true # disabled by default
spring.mobile.devicedelegatingviewresolver.normal-prefix=
spring.mobile.devicedelegatingviewresolver.normal-suffix=
spring.mobile.devicedelegatingviewresolver.mobile-prefix=mobile/
spring.mobile.devicedelegatingviewresolver.mobile-suffix=
spring.mobile.devicedelegatingviewresolver.tablet-prefix=tablet/
spring.mobile.devicedelegatingviewresolver.tablet-suffix=

MANAGEMENT HTTP SERVER (ManagementServerProperties)

management.port= # defaults to ‘server.port’
management.address= # bind to a specific NIC
management.context-path= # default to ‘/’
management.add-application-context-header= # default to true
management.security.enabled=true # enable security
management.security.role=ADMIN # role required to access the management endpoint
management.security.sessions=stateless # session creating policy to use (always, never, if_required, stateless)

PID FILE (ApplicationPidFileWriter)

spring.pidfile= # Location of the PID file to write

ENDPOINTS (AbstractEndpoint subclasses)

endpoints.autoconfig.id=autoconfig
endpoints.autoconfig.sensitive=true
endpoints.autoconfig.enabled=true
endpoints.beans.id=beans
endpoints.beans.sensitive=true
endpoints.beans.enabled=true
endpoints.configprops.id=configprops
endpoints.configprops.sensitive=true
endpoints.configprops.enabled=true
endpoints.configprops.keys-to-sanitize=password,secret,key # suffix or regex
endpoints.dump.id=dump
endpoints.dump.sensitive=true
endpoints.dump.enabled=true
endpoints.env.id=env
endpoints.env.sensitive=true
endpoints.env.enabled=true
endpoints.env.keys-to-sanitize=password,secret,key # suffix or regex
endpoints.health.id=health
endpoints.health.sensitive=true
endpoints.health.enabled=true
endpoints.health.mapping.*= # mapping of health statuses to HttpStatus codes
endpoints.health.time-to-live=1000
endpoints.info.id=info
endpoints.info.sensitive=false
endpoints.info.enabled=true
endpoints.mappings.enabled=true
endpoints.mappings.id=mappings
endpoints.mappings.sensitive=true
endpoints.metrics.id=metrics
endpoints.metrics.sensitive=true
endpoints.metrics.enabled=true
endpoints.shutdown.id=shutdown
endpoints.shutdown.sensitive=true
endpoints.shutdown.enabled=false
endpoints.trace.id=trace
endpoints.trace.sensitive=true
endpoints.trace.enabled=true

HEALTH INDICATORS (previously health.*)

management.health.db.enabled=true
management.health.diskspace.enabled=true
management.health.mongo.enabled=true
management.health.rabbit.enabled=true
management.health.redis.enabled=true
management.health.solr.enabled=true
management.health.diskspace.path=.
management.health.diskspace.threshold=10485760
management.health.status.order=DOWN, OUT_OF_SERVICE, UNKNOWN, UP

MVC ONLY ENDPOINTS

endpoints.jolokia.path=jolokia
endpoints.jolokia.sensitive=true
endpoints.jolokia.enabled=true # when using Jolokia

JMX ENDPOINT (EndpointMBeanExportProperties)

endpoints.jmx.enabled=true
endpoints.jmx.domain= # the JMX domain, defaults to ‘org.springboot’
endpoints.jmx.unique-names=false
endpoints.jmx.static-names=

JOLOKIA (JolokiaProperties)

jolokia.config.*= # See Jolokia manual

REMOTE SHELL

shell.auth=simple # jaas, key, simple, spring
shell.command-refresh-interval=-1
shell.command-path-patterns= # classpath*:/commands/, classpath*:/crash/commands/
shell.config-path-patterns= # classpath*:/crash/*
shell.disabled-commands=jpa*,jdbc*,jndi* # comma-separated list of commands to disable
shell.disabled-plugins=false # don’t expose plugins
shell.ssh.enabled= # ssh settings …
shell.ssh.key-path=
shell.ssh.port=
shell.telnet.enabled= # telnet settings …
shell.telnet.port=
shell.auth.jaas.domain= # authentication settings …
shell.auth.key.path=
shell.auth.simple.user.name=
shell.auth.simple.user.password=
shell.auth.spring.roles=

GIT INFO

spring.git.properties= # resource ref to generated git info properties file

解決SpringBoot連線池TOMCAT-JDBC(預設) DBCP或C3P0連線超時異常問題
配置資料來源連線池的時候如果沒有配置連線檢查或者超時回收,造成之後應用通過連線池getConnection時,都可能獲取到這些不可用的連線。druid沒有上述問題,因為預設有預設值。

隔多少時間回收廢棄連線 一般比minEvictableIdleTimeMillis小
spring.datasource.time-between-eviction-runs-millis=300000
指定執行每個eviction執行緒時的物件數量
spring.datasource.num-tests-per-eviction-run=3
指定一個空閒連線最少空閒多久後可被清除.
spring.datasource.min-evictable-idle-time-millis=3600000

上面的配置是配置資料來源回收連線,只要配置的回收時間小於mysql的超時時間就可以。

spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1

TestOnBorrow檢測池裡連線的可用性,假如連線池中的連線被資料庫關閉了,應用通過連線池getConnection時會重新建立。validationQuery是檢查時用的sql語句

SpringBoot1.4.1 需要分別單獨配置連線池的配置
比如使用hikari連線池
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=5

說在最後的話:編寫實屬不易,若喜歡或者對你有幫助記得點贊+關注或者收藏哦~