Spring Boot 配置大全(小结)

Spring Boot 允许通过外部配置让你在不同的环境使用同一应用程序的代码,简单说就是可以通过配置文件来注入属性或者修改默认的配置。

SpringBoot的配置方式有很多,它们的优先级如下所示(优先级递减顺序):

1.命令行参数
2.来自java:comp/env的JNDI属性
3.Java系统属性(System.getProperties())
4.操作系统环境变量
5.RandomValuePropertySource配置的random.*属性值
6.jar包外部的application-{profile}.properties或application.yml(带spring.profile)配置文件
7.jar包内部的application-{profile}.properties或application.yml(带spring.profile)配置文件
8.jar包外部的application.properties或application.yml(不带spring.profile)配置文件
9.jar包内部的application.properties或application.yml(不带spring.profile)配置文件
10.@Configuration注解类上的@PropertySource
11.通过SpringApplication.setDefaultProperties指定的默认属性

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
是使用<br/>这种形式,还是<br></br>这种展开模式,默认为: 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.

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • Spring Boot 日志配置方法(超详细)

    默认日志 Logback : 默认情况下,Spring Boot会用Logback来记录日志,并用INFO级别输出到控制台.在运行应用程序和其他例子时,你应该已经看到很多INFO级别的日志了. 从上图可以看到,日志输出内容元素具体如下: 时间日期:精确到毫秒 日志级别:ERROR, WARN, INFO, DEBUG or TRACE 进程ID 分隔符:- 标识实际日志的开始 线程名:方括号括起来(可能会截断控制台输出) Logger名:通常使用源代码的类名 日志内容 添加日志依赖 假如mave

  • 详解SpringBoot配置连接池

    内置的连接池 目前spring Boot中默认支持的连接池有dbcp,dbcp2, tomcat, hikari三种连接池. 数据库连接可以使用DataSource池进行自动配置. 由于Tomcat数据源连接池的性能和并发,在tomcat可用时,我们总是优先使用它. 如果HikariCP可用,我们将使用它. 如果Commons DBCP可用,我们将使用它,但在生产环境不推荐使用它. 最后,如果Commons DBCP2可用,我们将使用它. 以上的几种连接池,可以通过在配置application文

  • 深入理解Spring Boot属性配置文件

    前言 相信很多人选择Spring Boot主要是考虑到它既能兼顾Spring的强大功能,还能实现快速开发的便捷.我们在Spring Boot使用过程中,最直观的感受就是没有了原来自己整合Spring应用时繁多的XML配置内容,替代它的是在pom.xml中引入模块化的Starter POMs,其中各个模块都有自己的默认配置,所以如果不是特殊应用场景,就只需要在application.properties中完成一些属性配置就能开启各模块的应用. 在之前的各篇文章中都有提及关于application.

  • 详解spring boot 使用application.properties 进行外部配置

    application.properties大家都不陌生,我们在开发的时候,经常使用它来配置一些可以手动修改而且不用编译的变量,这样的作用在于,打成war包或者jar用于生产环境时,我们可以手动修改环境变量而不用再重新编译. spring boo默认已经配置了很多环境变量,例如,tomcat的默认端口是8080,项目的contextpath是"/"等等,可以在这里看spring boot默认的配置信息http://docs.spring.io/spring-boot/docs/curr

  • 详解spring boot配置单点登录

    概述 企业内部一般都有一套单点登录系统(常用的实现有apereo cas),所有的内部系统的登录认证都对接它.本文介绍spring boot的程序如何对接CAS服务. 常用的安全框架有spring security和apache shiro.shiro的配置和使用相对简单,本文使用shrio对接CAS服务. 配置 新增依赖 pom.xml新增: <properties> <shiro.version>1.2.4</shiro.version> </properti

  • Spring Boot 配置大全(小结)

    Spring Boot 允许通过外部配置让你在不同的环境使用同一应用程序的代码,简单说就是可以通过配置文件来注入属性或者修改默认的配置. SpringBoot的配置方式有很多,它们的优先级如下所示(优先级递减顺序): 1.命令行参数 2.来自java:comp/env的JNDI属性 3.Java系统属性(System.getProperties()) 4.操作系统环境变量 5.RandomValuePropertySource配置的random.*属性值 6.jar包外部的application

  • 详解Spring Boot配置排序依赖技巧

    本文主要介绍了Spring Boot配置排序依赖技巧,分享给大家,具体如下: Spring Boot - 被错误使用的注解 我自己曾经在 Spring Boot 中集成通用 Mapper 时,写过下面的代码: @Configuration @AutoConfigureAfter(MyBatisConfig.class) public class MyBatisMapperScannerConfig { //其他 } 这种用法我参考的 mybatis-spring-boot-starter. 由于

  • 详解spring boot配置 ssl

    ssl协议位于tcp/ip协议与各种应用协议之间,为数据通信提供安全支持. ssl协议分为两层: ssl记录协议,它建立在可靠传输协议之上,为高层协议提供数据封装.压缩.加密等基本功能支持. ssl握手协议,它建立在ssl记录协议之上,用于实际数据传输开始前,通信双方进行身份认证.协商加密算法.交换加密密钥等 基于B/S的web应用,是通过https来实现ssl的.https是http的安全版,即在http下加入ssl层,https的安全基础是ssl: 我们开始在spring boot中使用ss

  • 详解Spring Boot 配置多个RabbitMQ

    闲话 好久没有写博客了,6月份毕业,因为工作原因,公司上网受限,一直没能把学到的知识点写下来,工作了半年,其实学到的东西也不少,但是现在回忆起来的东西少之又少,有时甚至能在同个问题中踩了几次,越来越觉得及时记录一下学到的东西很重要. 好了,闲话少说,写下这段时间学习的东西,先记录一下用spring Boot配置多个RabbitMQ的情况... 最近公司新启动一个新平台的项目,需要用微服务这个这几年很火的概念来做,所以就学习了Spring Boot方面的知识,给同事展示Spring Boot的一些

  • Spring Boot 配置 IDEA和DevTools 热部署的方法

    MAVEN 配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/

  • 通过Spring Boot配置动态数据源访问多个数据库的实现代码

    之前写过一篇博客<Spring+Mybatis+Mysql搭建分布式数据库访问框架>描述如何通过Spring+Mybatis配置动态数据源访问多个数据库.但是之前的方案有一些限制(原博客中也描述了):只适用于数据库数量不多且固定的情况.针对数据库动态增加的情况无能为力. 下面讲的方案能支持数据库动态增删,数量不限. 数据库环境准备 下面一Mysql为例,先在本地建3个数据库用于测试.需要说明的是本方案不限数据库数量,支持不同的数据库部署在不同的服务器上.如图所示db_project_001.d

  • Spring Boot 配置MySQL数据库重连的操作方法

    使用jdbc连接MySQL,如果连接失效,可能会报类似的错误: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,371,623 milliseconds ago. The last packet sent successfully to the server was 78,860,631 millisecond

  • spring boot配置MySQL数据库连接、Hikari连接池和Mybatis的简单配置方法

    此方法为极简配置,支持MySQL数据库多库连接.支持Hikari连接池.支持MyBatis(包括Dao类和xml文件位置的配置). 1.pom.xml中引入依赖: <!-- Begin of DB related --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId>

  • Spring Boot配置过滤器的2种方式示例

    前言 过滤器(Filter)是Servlet中常用的技术,可以实现用户在访问某个目标资源之前,对访问的请求和响应进行拦截,常用的场景有登录校验.权限控制.敏感词过滤等,下面介绍下Spring Boot配置过滤器的两种方式. 一.@WebFilter注解方式 使用@WebFilter注解为声明当前类为filter,第一个参数为该filter起一个名字,第二个参数为说明要拦截的请求地址,当前类需要实现Filter接口,里面有三个方法,分别为过滤器初始化.过滤方法和过滤器销毁. @Slf4j @Web

随机推荐