spring boot 笔记之注解大全及疑问解读

Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。它已经成为地球上最热门的技术之一。

首先你要达到系统化入门级,我给你推荐的图书:《Java EE开发的颠覆者 Spring Boot实战》和《Spring Boot参考指南》。

目录

1.application.yml和bootstrap.yml区别?

2.springboot新增改进注解

3.@ConfigurationProperties vs @Value?

4. @Configuration vs Auto-configuration

5.源码相关解读

6.常见jar迁移 

7. 其他问题

7.1 Servlet容器选择 Undertow而非Tomcat和Jetty

8. 配置属性系列

8.1 server

8.1.1 server

8.1.2 cookie / session

8.1.3 tomcat

8.1.4 undertow

8.1.3 ssl

8.2 MVC

8.2.1 MVC

8.2.2 http

8.2.3 view

8.2.4 multipart

8.2.5 json

8.2.6 resource

8.2.7 messages

8.2.8 freemarker

8.2.9 velocity

8.2.10 thymeleaf

8.2.11 mustcache

8.2.12 jersey

8.2.13 mobile

8.2.14 groovy

8.3 datasource

8.3.1 datasource

8.3.2 JPA

8.3.3 jooq

8.3.4 h2

8.3.4 JTA

8.4 cache

8.5 redis

8.6 mongodb

8.7 springdata

8.8 mq

8.8.1 rabbitmq

8.8.2 activemq

8.8.3 jms

8.9 spring security

8.10 其他

8.10.1 aop

8.10.2 application

8.10.3 autoconfig

8.10.4 batch

8.10.5 jmx

8.10.6 mail

8.10.7 sendgrid

8.10.8 social


1.application.yml和bootstrap.yml区别?

application.yml 是应用级别的配置 bootstrap.yml是系统级别的配,一般不变的放到bootstrap.yml 需要随业务变得放到application.yml

2.springboot新增改进注解

根据颜色划分为多个块,便于理解。

注解

版本

描述

@Resource 

-

JavaEE5规范

@PostConstruct

-

JavaEE5规范

@PreDestroy

-

JavaEE5规范

@Autowired 

2.5

@Qualifier

2.5

新改进特性:可以单独在方法中使用

@Required

2.0

@Scope

2.5

@Value

3.0

@PropertySource

3.1

加载属性文件,绑定值,必须使用properties文件

@PropertySources

4.0

PropertySource的集合形式

@Repository      

2.0

@Service

2.5

@Component      

2.5

@Bean

3.0

生产bean

@DependsOn

3.0

控制依赖bean加载顺序

@Lazy

3.0

Bean懒加载

@Import

3.0

可导入Configuration、component classes、

ImportSelector、ImportResource

@ImportResource

3.0

导入XML配置文件

@Primary

3.0

在自动装配时这个bean应该优先当多个候选人资格(相同类型的bean)

@ComponentScan                 

3.1

扫描包,可定义@Filter

@Filter

3.1

扫描包过滤配置

@Configuration

3.0

表明这个是可以声明一个或多个@Bean的配置类

@ActiveProfiles  

3.1

单元测试中指定环境变量

@Profile

3.1

多环节

@SpringBootApplication 

1.2.0

表明这是一个spring-boot启动类,等价于@Configuration,@ComponentScan,

@EnableAutoConfiguration

@SpringBootConfiguration

1.4.0

表明这个类提供了spring-boot启动应用程序

@EnableAutoConfiguration

1.3.0

启用自动配置Spring应用程序上下文,它自动根据您的类路径来获取spi(spring.factories)中这些的bean的定义。

@ConfigurationProperties

1.3.0

绑定属性值,适用于类或方法(第三方组件),支持javax.validation注解校验

@EnableConfigurationProperties 

1.3.0

开启对@ConfigurationProperties注解配置Bean的支持

@ConfigurationPropertiesBinding

1.3.0

ConfigurationProperties绑定属性时属性转换

@AutoConfigureAfter

1.3.0

 auto-configuration

@AutoConfigureBefore

1.3.0

 auto-configuration

@AutoconfigureOrder

1.3.0

 auto-configuration

@Conditional 

4.0

该类下面的所有@Bean都会启用配置

@ConditionalOnClass

1.3.0

某个class位于类路径上,才会实例化一个Bean

@ConditionalOnMissingClass

1.3.0

某个class类路径上不存在的时候,才会实例化一个Bean

@ConditionalOnBean

1.3.0

Bean条件

@ConditionalOnMissingBean 

1.3.0

反之

@ConditionalOnProperty         

1.1.0

Property条件

@ConditionalOnResource

1.3.0

Resource条件

@ConditionalOnWebApplication  

1.3.0

WebApplication条件

@ConditionalOnNotWebApplication

1.3.0

反之

@ConditionalOnExpression       

1.3.0

SpEL表达式条件

@ConditionalOnJndi

1.2.0

基于JNDI的可用性相匹

@ConditionalOnJava

1.1.0

指定JVM版本

@ConditionalOnCloudPlatform

1.5.0

指定的云平台

@EnableAsync

3.1

异步任务的启用

@Async

3.0

异步任务方法或者异步类

@EnableScheduling

3.1

计划任务的启用

@Scheduled

3.0

声明这是一个计划任务,方法返回类型为void,支持cron、fixDelay、fixRate

@EnableWebSocketMessagetBroker

4.0

webSocket启用

@MessageMapping 

4.0

websocket

@EnableAspectJAutoProxy

3.1

AOP启用

@Aspect

-

aspectj

@PointCut

-

aspectj

@Before

-

aspectj

@After

-

aspectj

@Around

-

aspectj

@AfterReturning

-

aspectj

@AfterThrowing

-

aspectj

@EnableCaching             

3.1

缓存启用

@Cacheable

3.1

对其结果进行缓存

@Caching

3.1

组合多个Cache注解使用

@CacheEvict         

3.1

根据一定的条件对缓存进行清空

@CachePut          

3.1

和 @Cacheable 不同的是,它每次执行前不会去检查缓存,都会触发真实方法的调用

@CacheConfig 

4.1

类级别的注解,对词重复(方法多次指定cacheNames的)定义的改进

@Controller      

2.5

@RequestMapping  

2.5

@ControllerAdvice

3.2

方法将应用于所有控制器,可以结合@ExceptionHandler、@InitBinder、@ModelAttribute使用

@RestControllerAdvice

4.3

为ControllerAdvice和ResponseBody的组合体

@CookieValue

3.0

@SessionAttributes

2.5

@SessionAttribute

4.3

将方法参数绑定到一个会话属性

@CrossOrigin                  

4.2

ajax跨域

@ExceptionHandler

3.0

处理异常的具体处理程序类和/或处理程序方法

@ResponseStatus

3.1

标志着一个方法或异常类状态应该返回

@MatrixVariable

3.2

矩阵变量绑定参数(Map型参数)

如:/path;name=value;name2=value2

@InitBinder

2.5

WebDataBinder用来自动绑定前台参数到mdel中

@ModelAttribute  

2.5

@RequestMapping     

2.5

@RequestAttribute

4.3

将方法参数绑定到请求属性

@RequestParam      

2.5

@PathVariable      

3.0

@RequestBody        

3.0

@ResponseBody      

3.0

@RequestHeader      

3.0

@RequestPart

3.1

绑定“multipart/form-data”参数

@WebAppConfiguration

3.2

@WebAppConfiguration

@EnableWebMvc                 

3.1

开启Web Mvc支持

@RestController

4.0

为@Controller和@ResponseBody组合体

@ServletComponentScan

1.3.0

注入@WebServlet,@WebFilter,

@WebListener的类

@GetMapping

4.3

组合注解,是@RequestMapping(method = RequestMethod.GET)的缩写

@PostMapping

4.3

同上

@PutMapping

4.3

同上

@DeleteMapping 

4.3

同上

@PatchMapping

4.3

同上

@JsonComponent

1.4.0

自定义JSON序列化器和反序列化器

@EnableTransactionManagement

3.1

事务启用

@Transactional

1.2

@NoRepositoryBean

?

JPA

@EnableJpaRepositories

?

JPA

@EntityScan

1.4.0

JPA

@Entity

?

JPA

@Embeddable

?

JPA

@MappedSuperclass

?

JPA

@NodeEntity

?

 Neo4j

@EnableNeo4jRepositories

?

 Neo4j

@SolrDocument

?

 Solr

@Document

?

 Elasticsearch

@ManagementContextConfiguration  

1.3.0

Actuator模块

@ExportMetricWriter

1.3.0

Actuator模块

@ExportMetricReader

1.3.0

Actuator模块

@EnableMBeanExport

3.2

JMX Mbean启用

@ManagedResource

1.2

类的所有实例标识为JMX受控资源

@ManagedOperation

1.2

将方法标识为JMX操作

@ManagedAttribute

1.2

将getter或者setter标识为部分JMX属性

@ManagedOperationParameter

1.2

定义操作参数说明

@ManagedOperationParameters

1.2

定义操作参数说明

@EnableSpringSecurity

?

开启spring seccurity支持

@EnableGlobalMethodSecurity

?

启用'basic'认证

@EnableAuthorizationServer

?

oauth2 access tokens

@EnableOAuth2Client

?

安全

@EnableOAuth2Sso

?

安全

@EnableIntegration

?

启用spring-boot-starter-integration基于消息和其他传输协议的抽象,比如HTTP,TCP等

@EnableJms

?

开启JMS支持

@JmsListener

?

创建一个监听者端点,默认是支持事务性的

@EnableRabbit 

?

开启Rabbit支持(AMQP)

@RabbitListener

?

创建一个监听者端点

@ContextConfiguration

2.5

集成化测试中定义加载及配置ApplicationContext。

Spring 3.1之前,只有基于路径的资源位置(通常是XML配置文件)的支持,Spring 4.0.4

@SpringBootTest  

1.4.0

Test模块,并添加

@RunWith(SpringRunner.class)    

@TestConfiguration

1.4.0

类似@Configuration

@TestComponent

1.4.0

类似@Component

@LocalServerPort

1.4.0

用于注入测试用例实际使用的端口

@MockBean

1.4.0

需Mock的bean

@SpyBean

1.4.0

获得代理对象相当于

Mockito.spy(MethodTest.class)

@JsonTest

1.4.0

测试对象JSON序列化和反序列化是否工作正常

@AutoConfigureJsonTesters

1.4.0

启用和配置的JSON的自动测试

@WebMvcTest

1.4.0

检测单个Controller是否工作正常

@AutoConfigureMockMvc

1.4.0

注解一个non-@WebMvcTest的类

@DataJpaTest

1.4.0

JPA测试

@AutoConfigureTestEntityManager

1.4.0

JPA

@AutoConfigureTestDatabase     

1.4.0

真实DB/嵌入DB

@RestClientTest

1.4.0

针对rest客户端测试

@AutoConfigureRestDocs

1.4.0

开启了restdocs生成snippets文件,并指定了存放位置

3.@ConfigurationProperties vs @Value?

 @ConfigurationProperties@Value
功能批量注入配置文件中属性一个个指定
松散绑定YesNo
SpEL表达式NoYes
JSR303数据校验YesNo
复杂类型封装YesNo
Configuration Metadata
配置项友好提示
YesNO

Relaxed(松散绑定)绑定,Environment属性名和bean属性名不需要精确匹配。

属性                                     说明
person.firstName                标准驼峰规则
person.first-name               虚线表示,推荐用于.properties和.yml文件中
person.first_name              下划线表示,用于.properties和.yml文件的可选格式
PERSON_FIRST_NAME   大写形式,使用系统环境变量时推荐

4. @Configuration vs Auto-configuration

@Configuration替代xml来定义BeanDefinition的一种手段。Auto-configuration也是定义BeanDefinition的一种手段,也就是spring spi(META-INF/spring.factories)读取出来的key为org.springframework.boot.autoconfigure.EnableAutoConfiguration的配置类,简称为EnableAutoConfiguration加载。

这两者的相同之处有

  • 都是使用@Configuration注解的类,这些类里都可以定义@Bean、@Import、@ImportResource。
  • 都可以使用@Condition*来根据情况选择是否加载

而不同之处有

  • 加载方式不同:普通@Configuration则是通过扫描package path加载的,Auto-configuration的是通过读取classpath*:META-INF/spring.factories中EnableAutoConfiguration
  • 加载顺序不同,普通@Configuration的加载永远在Auto-configuration之前
  • 内部加载顺序可控上的不同:普通@Configuration则无法控制加载顺序,Auto-configuration可以使用@AutoConfigureOrder、@AutoConfigureBefore、@AutoConfigureAfter

5.源码相关解读

首先如果你对spring3.x或2.x系列源码不太熟悉,spring boot的源码可能对你而言非常难,不过你也大可不必为此而烦恼,本来度源码讲究的就是领悟力,不一定要全部掌握的。

先了解这些吧:

  • AbstractApplicationContext
  • AnnotationConfigApplicationContext
  • AnnotatedBeanDefinitionReader
  • ClassPathBeanDefinitionScanner
  • EventPublishingRunListener
  • SimpleApplicationEventMulticaster
  • ApplicationStartedEvent / ApplicationEnvironmentPreparedEvent / ApplicationFailedEvent

再看spring boot相关的:

  •  JarLaucher
  •  Archive
  • SpringApplication
  • SpringFactoriesLoader
  • ApplicationContextInitializer
  • ConfigurationClassPostProcessor
  • AnnotationConfigServletWebServerApplicationContext

是的,如果你都知道上面这些对象是做什么的话,那你已经进阶了。不了解的也不要可以看这些文章:

6.常见jar迁移 

为了更好的迎合spring boot的理念,我想jar迁移恐怕是少不了了。

  druid ->             druid-spring-boot-starter
  mybatis-spring -> mybatis-spring-boot-starter:MybatisAutoConfiguration(自动注入@Mapper)
  jedis ->            pring-boot-starter-data-redis

 ...

7. 其他问题

7.1 Servlet容器选择 Undertow而非Tomcat和Jetty

2017年1月26日发布的有个老外做了个相当有参考性的性能测试:Tomcat vs. Jetty vs. Undertow: Comparison of Spring Boot Embedded Servlet Containers ,环境:Java 8,Maven 3.3.9, Spring 1.4.3, Tomcat 8.5.6, Jetty 9.3.14 and Undertow 1.3.24。

最终结论是:所有三个嵌入式servlet容器都具有类似的性能,但在Tomcat和Jetty紧随其后的情况下,Undertow似乎具有最佳的性能。Jetty启动时的内存占用是311 MB最大的。Tomcat和Undertow的初始化后内存也很低,大约120MB,而Undertow的最低内存是114MB。响应头中的关键区别在于,默认情况下,undertow包含HTTP持久连接。此头将用于支持持久连接的客户端,以通过重用连接详细信息来优化性能。

8. 配置属性系列

8.1 server

8.1.1 server

  • server.address
    指定server绑定的地址

  • server.compression.enabled
    是否开启压缩,默认为false.

  • server.compression.excluded-user-agents
    指定不压缩的user-agent,多个以逗号分隔,默认值为:text/html,text/xml,text/plain,text/css

  • server.compression.mime-types
    指定要压缩的MIME type,多个以逗号分隔.

  • server.compression.min-response-size
    执行压缩的阈值,默认为2048

  • server.context-parameters.[param name]
    设置servlet context 参数

  • server.context-path
    设定应用的context-path.

  • server.display-name
    设定应用的展示名称,默认: application

  • server.jsp-servlet.class-name
    设定编译JSP用的servlet,默认: org.apache.jasper

8.1.2 cookie / session

  • server.session.cookie.comment
    指定session cookie的comment

  • server.session.cookie.domain
    指定session cookie的domain

  • server.session.cookie.http-only
    是否开启HttpOnly.

  • server.session.cookie.max-age
    设定session cookie的最大age.

  • server.session.cookie.name
    设定Session cookie 的名称.

  • server.session.cookie.path
    设定session cookie的路径.

  • server.session.cookie.secure
    设定session cookie的“Secure” flag.

  • server.session.persistent
    重启时是否持久化session,默认false

  • server.session.timeout
    session的超时时间

  • server.session.tracking-modes
    设定Session的追踪模式(cookie, url, ssl).

8.1.3 tomcat

  • server.tomcat.access-log-enabled
    是否开启access log ,默认: false)

  • server.tomcat.access-log-pattern
    设定access logs的格式,默认: common

  • server.tomcat.accesslog.directory
    设定log的目录,默认: logs

  • server.tomcat.accesslog.enabled
    是否开启access log,默认: false

  • server.tomcat.accesslog.pattern
    设定access logs的格式,默认: common

  • server.tomcat.accesslog.prefix
    设定Log 文件的前缀,默认: access_log

  • server.tomcat.accesslog.suffix
    设定Log 文件的后缀,默认: .log

  • server.tomcat.background-processor-delay
    后台线程方法的Delay大小: 30

  • server.tomcat.basedir
    设定Tomcat的base 目录,如果没有指定则使用临时目录.

  • 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}| 172\.1[6-9]{1}\.\d{1,3}\.\d{1,3}| 172\.2[0-9]{1}\.\d{1,3}\.\d{1,3}|172\.3[0-1]{1}\.\d{1,3}\.\d{1,3}”

  • server.tomcat.max-http-header-size
    设定http header的最小值,默认: 0

  • server.tomcat.max-threads
    设定tomcat的最大工作线程数,默认为: 0

  • server.tomcat.port-header
    设定http header使用的,用来覆盖原来port的value.

  • server.tomcat.protocol-header
    设定Header包含的协议,通常是 X-Forwarded-Proto,如果remoteIpHeader有值,则将设置为RemoteIpValve.

  • server.tomcat.protocol-header-https-value
    设定使用SSL的header的值,默认https.

  • server.tomcat.remote-ip-header
    设定remote IP的header,如果remoteIpHeader有值,则设置为RemoteIpValve

  • server.tomcat.uri-encoding
    设定URI的解码字符集.

8.1.4 undertow

  • server.undertow.access-log-dir
    设定Undertow access log 的目录,默认: logs

  • server.undertow.access-log-enabled
    是否开启access log,默认: false

  • server.undertow.access-log-pattern
    设定access logs的格式,默认: common

  • server.undertow.accesslog.dir
    设定access log 的目录.

  • server.undertow.buffer-size
    设定buffer的大小.

  • server.undertow.buffers-per-region
    设定每个region的buffer数

  • server.undertow.direct-buffers
    设定堆外内存

  • server.undertow.io-threads
    设定I/O线程数.

  • server.undertow.worker-threads
    设定工作线程数

8.1.3 ssl

  • server.ssl.ciphers
    是否支持SSL ciphers.

  • server.ssl.client-auth
    设定client authentication是wanted 还是 needed.

  • server.ssl.enabled
    是否开启ssl,默认: true

  • server.ssl.key-alias
    设定key store中key的别名.

  • server.ssl.key-password
    访问key store中key的密码.

  • server.ssl.key-store
    设定持有SSL certificate的key store的路径,通常是一个.jks文件.

  • server.ssl.key-store-password
    设定访问key store的密码.

  • server.ssl.key-store-provider
    设定key store的提供者.

  • server.ssl.key-store-type
    设定key store的类型.

  • server.ssl.protocol
    使用的SSL协议,默认: TLS

  • server.ssl.trust-store
    持有SSL certificates的Trust store.

  • server.ssl.trust-store-password
    访问trust store的密码.

  • server.ssl.trust-store-provider
    设定trust store的提供者.

  • server.ssl.trust-store-type
    指定trust store的类型.

8.2 MVC

8.2.1 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视图的后缀.

8.2.2 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

8.2.3 view

  • spring.view.prefix
    设定mvc视图的前缀.

  • spring.view.suffix
    设定mvc视图的后缀.

8.2.4 multipart

  • multipart.enabled
    是否开启文件上传支持,默认为true

  • multipart.file-size-threshold
    设定文件写入磁盘的阈值,单位为MB或KB,默认为0

  • multipart.location
    指定文件上传路径.

  • multipart.max-file-size
    指定文件大小最大值,默认1MB

  • multipart.max-request-size
    指定每次请求的最大值,默认为10MB

8.2.5 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.

8.2.6 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:/

8.2.7 messages

  • spring.messages.basename
    指定message的basename,多个以逗号分隔,如果不加包名的话,默认从classpath路径开始,默认: messages

  • spring.messages.cache-seconds
    设定加载的资源文件缓存失效时间,-1的话为永不过期,默认为-1

  • spring.messages.encoding
    设定Message bundles的编码,默认: UTF-8

8.2.8 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
    指定使用模板的视图列表.

8.2.9 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
    设定需要解析的视图名称.

8.2.10 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
    指定使用模板的视图名,多个以逗号分隔.

8.2.11 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
    指定要使用模板的视图名.

8.2.12 jersey

  • spring.jersey.filter.order
    指定Jersey filter的order,默认为: 0

  • spring.jersey.init
    指定传递给Jersey的初始化参数.

  • spring.jersey.type
    指定Jersey的集成类型,可以是servlet或者filter.

8.2.13 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

8.2.14 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
    指定要使用模板的视图名称.

8.3 datasource

8.3.1 datasource

  • spring.dao.exceptiontranslation.enabled
    是否开启PersistenceExceptionTranslationPostProcessor,默认为true

  • spring.datasource.abandon-when-percentage-full
    设定超时被废弃的连接占到多少比例时要被关闭或上报

  • spring.datasource.allow-pool-suspension
    使用Hikari pool时,是否允许连接池暂停,默认为: false

  • spring.datasource.alternate-username-allowed
    是否允许替代的用户名.

  • spring.datasource.auto-commit
    指定updates是否自动提交.

  • spring.datasource.catalog
    指定默认的catalog.

  • spring.datasource.commit-on-return
    设置当连接被归还时,是否要提交所有还未完成的事务

  • spring.datasource.connection-init-sql
    指定连接被创建,再被添加到连接池之前执行的sql.

  • spring.datasource.connection-init-sqls
    使用DBCP connection pool时,指定初始化时要执行的sql

  • spring.datasource.connection-properties.[key]
    在使用DBCP connection pool时指定要配置的属性

  • spring.datasource.connection-test-query
    指定校验连接合法性执行的sql语句

  • spring.datasource.connection-timeout
    指定连接的超时时间,毫秒单位.

  • spring.datasource.continue-on-error
    在初始化数据库时,遇到错误是否继续,默认false

  • spring.datasource.data
    指定Data (DML)脚本

  • spring.datasource.data-source-class-name
    指定数据源的全限定名.

  • spring.datasource.data-source-jndi
    指定jndi的地址

  • spring.datasource.data-source-properties.[key]
    使用Hikari connection pool时,指定要设置的属性

  • spring.datasource.db-properties
    使用Tomcat connection pool,指定要设置的属性

  • spring.datasource.default-auto-commit
    是否自动提交.

  • spring.datasource.default-catalog
    指定连接默认的catalog.

  • spring.datasource.default-read-only
    是否设置默认连接只读.

  • spring.datasource.default-transaction-isolation
    指定连接的事务的默认隔离级别.

  • spring.datasource.driver-class-name
    指定driver的类名,默认从jdbc url中自动探测.

  • spring.datasource.fair-queue
    是否采用FIFO返回连接.

  • spring.datasource.health-check-properties.[key]
    使用Hikari connection pool时,在心跳检查时传递的属性

  • spring.datasource.idle-timeout
    指定连接多久没被使用时,被设置为空闲,默认为10ms

  • spring.datasource.ignore-exception-on-pre-load
    当初始化连接池时,是否忽略异常.

  • spring.datasource.init-sql
    当连接创建时,执行的sql

  • spring.datasource.initial-size
    指定启动连接池时,初始建立的连接数量

  • spring.datasource.initialization-fail-fast
    当创建连接池时,没法创建指定最小连接数量是否抛异常

  • spring.datasource.initialize
    指定初始化数据源,是否用data.sql来初始化,默认: true

  • spring.datasource.isolate-internal-queries
    指定内部查询是否要被隔离,默认为false

  • spring.datasource.jdbc-interceptors
    使用Tomcat connection pool时,指定jdbc拦截器,分号分隔

  • spring.datasource.jdbc-url
    指定JDBC URL.

  • spring.datasource.jmx-enabled
    是否开启JMX,默认为: false

  • spring.datasource.jndi-name
    指定jndi的名称.

  • spring.datasource.leak-detection-threshold
    使用Hikari connection pool时,多少毫秒检测一次连接泄露.

  • spring.datasource.log-abandoned
    使用DBCP connection pool,是否追踪废弃statement或连接,默认为: false

  • spring.datasource.log-validation-errors
    当使用Tomcat connection pool是否打印校验错误.

  • spring.datasource.login-timeout
    指定连接数据库的超时时间.

  • spring.datasource.max-active
    指定连接池中最大的活跃连接数.

  • spring.datasource.max-age
    指定连接池中连接的最大年龄

  • spring.datasource.max-idle
    指定连接池最大的空闲连接数量.

  • spring.datasource.max-lifetime
    指定连接池中连接的最大生存时间,毫秒单位.

  • spring.datasource.max-open-prepared-statements
    指定最大的打开的prepared statements数量.

  • spring.datasource.max-wait
    指定连接池等待连接返回的最大等待时间,毫秒单位.

  • spring.datasource.maximum-pool-size
    指定连接池最大的连接数,包括使用中的和空闲的连接.

  • spring.datasource.min-evictable-idle-time-millis
    指定一个空闲连接最少空闲多久后可被清除.

  • spring.datasource.min-idle
    指定必须保持连接的最小值(For DBCP and Tomcat connection pools)

  • spring.datasource.minimum-idle
    指定连接维护的最小空闲连接数,当使用HikariCP时指定.

  • spring.datasource.name
    指定数据源名.

  • spring.datasource.num-tests-per-eviction-run
    指定运行每个idle object evictor线程时的对象数量

  • spring.datasource.password
    指定数据库密码.

  • spring.datasource.platform
    指定schema要使用的Platform(schema-${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的属性

8.3.2 JPA

  • spring.jpa.database
    指定目标数据库.

  • spring.jpa.database-platform
    指定目标数据库的类型.

  • spring.jpa.generate-ddl
    是否在启动时初始化schema,默认为false

  • spring.jpa.hibernate.ddl-auto
    指定DDL mode (none, validate, update, create, create-drop). 当使用内嵌数据库时,默认是create-drop,否则为none.

  • spring.jpa.hibernate.naming-strategy
    指定命名策略.

  • spring.jpa.open-in-view
    是否注册OpenEntityManagerInViewInterceptor,绑定JPA EntityManager到请求线程中,默认为: true

  • spring.jpa.properties
    添加额外的属性到JPA provider.

  • spring.jpa.show-sql
    是否开启sql的log,默认为: false

8.3.3 jooq

spring.jooq.sql-dialect
指定JOOQ使用的SQLDialect,比如POSTGRES.

8.3.4 h2

  • spring.h2.console.enabled
    是否开启控制台,默认为false

  • spring.h2.console.path
    指定控制台路径,默认为: /h2-console

8.3.4 JTA

  • spring.jta.allow-multiple-lrc
    是否允许 multiple LRC,默认为: false

  • spring.jta.asynchronous2-pc
    指定两阶段提交是否可以异步,默认为: false

  • spring.jta.background-recovery-interval
    指定多少分钟跑一次recovery process,默认为: 1

  • spring.jta.background-recovery-interval-seconds
    指定多久跑一次recovery process,默认: 60

  • spring.jta.current-node-only-recovery
    是否过滤掉其他非本JVM的recovery,默认为: true

  • spring.jta.debug-zero-resource-transaction
    是否追踪没有使用指定资源的事务,默认为: false

  • spring.jta.default-transaction-timeout
    设定默认的事务超时时间,默认为60

  • spring.jta.disable-jmx
    是否禁用jmx,默认为false

  • spring.jta.enabled
    是否开启JTA support,默认为: true

  • spring.jta.exception-analyzer
    设置指定的异常分析类

  • spring.jta.filter-log-status
    使用Bitronix Transaction Manager时,是否写mandatory logs,开启的话,可以节省磁盘空间,但是调试会复杂写,默认为false

  • spring.jta.force-batching-enabled
    使用Bitronix Transaction Manager时,是否批量写磁盘,默认为true.

  • spring.jta.forced-write-enabled
    使用Bitronix Transaction Manager时,是否强制写日志到磁盘,默认为true

  • spring.jta.graceful-shutdown-interval
    当使用Bitronix Transaction Manager,指定shutdown时等待事务结束的时间,超过则中断,默认为60

  • spring.jta.jndi-transaction-synchronization-registry-name
    当使用Bitronix Transaction Manager时,在JNDI下得事务同步registry,默认为: java:comp/TransactionSynchronizationRegistry

  • spring.jta.jndi-user-transaction-name
    指定在JNDI使用Bitronix Transaction Manager的名称,默认:java:comp/UserTransaction

  • spring.jta.journal
    当使用Bitronix Transaction Manager,指定The journal是否disk还是null还是一个类的全限定名,默认disk

  • spring.jta.log-dir
    Transaction logs directory.

  • spring.jta.log-part1-filename
    指定The journal fragment文件1的名字,默认: btm1.tlog

  • spring.jta.log-part2-filename
    指定The journal fragment文件2的名字,默认: btm2.tlog

  • spring.jta.max-log-size-in-mb
    指定journal fragments大小的最大值. 默认: 2M

  • spring.jta.resource-configuration-filename
    指定Bitronix Transaction Manager配置文件名.

  • spring.jta.server-id
    指定Bitronix Transaction Manager实例的id.

  • spring.jta.skip-corrupted-logs
    是否忽略corrupted log files文件,默认为false.

  • spring.jta.transaction-manager-id
    指定Transaction manager的唯一标识.

  • spring.jta.warn-about-zero-resource-transaction
    当使用Bitronix Transaction Manager时,是否对没有使用指定资源的事务进行警告,默认为: true

8.4 cache

  • spring.cache.cache-names
    指定要创建的缓存的名称,逗号分隔(若该缓存实现支持的话)

  • spring.cache.ehcache.config
    指定初始化EhCache时使用的配置文件的位置指定.

  • spring.cache.guava.spec
    指定创建缓存要使用的spec,具体详见CacheBuilderSpec.

  • spring.cache.hazelcast.config
    指定初始化Hazelcast时的配置文件位置

  • spring.cache.infinispan.config
    指定初始化Infinispan时的配置文件位置.

  • spring.cache.jcache.config
    指定jcache的配置文件.

  • spring.cache.jcache.provider
    指定CachingProvider实现类的全限定名.

  • spring.cache.type
    指定缓存类型

8.5 redis

  • spring.redis.database
    指定连接工厂使用的Database index,默认为: 0

  • spring.redis.host
    指定Redis server host,默认为: localhost

  • spring.redis.password
    指定Redis server的密码

  • spring.redis.pool.max-active
    指定连接池最大的活跃连接数,-1表示无限,默认为8

  • spring.redis.pool.max-idle
    指定连接池最大的空闲连接数,-1表示无限,默认为8

  • spring.redis.pool.max-wait
    指定当连接池耗尽时,新获取连接需要等待的最大时间,以毫秒单位,-1表示无限等待

  • spring.redis.pool.min-idle
    指定连接池中空闲连接的最小数量,默认为0

  • spring.redis.port
    指定redis服务端端口,默认: 6379

  • spring.redis.sentinel.master
    指定redis server的名称

  • spring.redis.sentinel.nodes
    指定sentinel节点,逗号分隔,格式为host:port.

  • spring.redis.timeout
    指定连接超时时间,毫秒单位,默认为0

8.6 mongodb

  • spring.mongodb.embedded.features
    指定要开启的特性,逗号分隔.

  • spring.mongodb.embedded.version
    指定要使用的版本,默认: 2.6.10

8.7 springdata

  • spring.data.elasticsearch.cluster-name
    指定es集群名称,默认: elasticsearch

  • spring.data.elasticsearch.cluster-nodes
    指定es的集群,逗号分隔,不指定的话,则启动client node.

  • spring.data.elasticsearch.properties
    指定要配置的es属性.

  • spring.data.elasticsearch.repositories.enabled
    是否开启es存储,默认为: true

  • spring.data.jpa.repositories.enabled
    是否开启JPA支持,默认为: true

  • spring.data.mongodb.authentication-database
    指定鉴权的数据库名

  • spring.data.mongodb.database
    指定mongodb数据库名

  • spring.data.mongodb.field-naming-strategy
    指定要使用的FieldNamingStrategy.

  • spring.data.mongodb.grid-fs-database
    指定GridFS database的名称.

  • spring.data.mongodb.host
    指定Mongo server host.

  • spring.data.mongodb.password
    指定Mongo server的密码.

  • spring.data.mongodb.port
    指定Mongo server port.

  • spring.data.mongodb.repositories.enabled
    是否开启mongodb存储,默认为true

  • spring.data.mongodb.uri
    指定Mongo database URI.默认:mongodb://localhost/test

  • spring.data.mongodb.username
    指定登陆mongodb的用户名.

  • spring.data.rest.base-path
    指定暴露资源的基准路径.

  • spring.data.rest.default-page-size
    指定每页的大小,默认为: 20

  • spring.data.rest.limit-param-name
    指定limit的参数名,默认为: size

  • spring.data.rest.max-page-size
    指定最大的页数,默认为1000

  • spring.data.rest.page-param-name
    指定分页的参数名,默认为: page

  • spring.data.rest.return-body-on-create
    当创建完实体之后,是否返回body,默认为false

  • spring.data.rest.return-body-on-update
    在更新完实体后,是否返回body,默认为false

  • spring.data.rest.sort-param-name
    指定排序使用的key,默认为: sort

  • spring.data.solr.host
    指定Solr host,如果有指定了zk的host的话,则忽略。默认为: http://127.0.0.1:8983/solr

  • spring.data.solr.repositories.enabled
    是否开启Solr repositories,默认为: true

  • spring.data.solr.zk-host
    指定zk的地址,格式为HOST:PORT.

8.8 mq

8.8.1 rabbitmq

  • spring.rabbitmq.addresses
    指定client连接到的server的地址,多个以逗号分隔.

  • spring.rabbitmq.dynamic
    是否创建AmqpAdmin bean. 默认为: true)

  • spring.rabbitmq.host
    指定RabbitMQ host.默认为: localhost)

  • spring.rabbitmq.listener.acknowledge-mode
    指定Acknowledge的模式.

  • spring.rabbitmq.listener.auto-startup
    是否在启动时就启动mq,默认: true)

  • spring.rabbitmq.listener.concurrency
    指定最小的消费者数量.

  • spring.rabbitmq.listener.max-concurrency
    指定最大的消费者数量.

  • spring.rabbitmq.listener.prefetch
    指定一个请求能处理多少个消息,如果有事务的话,必须大于等于transaction数量.

  • spring.rabbitmq.listener.transaction-size
    指定一个事务处理的消息数量,最好是小于等于prefetch的数量.

  • spring.rabbitmq.password
    指定broker的密码.

  • spring.rabbitmq.port
    指定RabbitMQ 的端口,默认: 5672)

  • spring.rabbitmq.requested-heartbeat
    指定心跳超时,0为不指定.

  • spring.rabbitmq.ssl.enabled
    是否开始SSL,默认: false)

  • spring.rabbitmq.ssl.key-store
    指定持有SSL certificate的key store的路径

  • spring.rabbitmq.ssl.key-store-password
    指定访问key store的密码.

  • spring.rabbitmq.ssl.trust-store
    指定持有SSL certificates的Trust store.

  • spring.rabbitmq.ssl.trust-store-password
    指定访问trust store的密码.

  • spring.rabbitmq.username
    指定登陆broker的用户名.

  • spring.rabbitmq.virtual-host
    指定连接到broker的Virtual host.

8.8.2 activemq

  • spring.activemq.broker-url
    指定ActiveMQ broker的URL,默认自动生成.

  • spring.activemq.in-memory
    是否是内存模式,默认为true.

  • spring.activemq.password
    指定broker的密码.

  • spring.activemq.pooled
    是否创建PooledConnectionFactory,而非ConnectionFactory,默认false

  • spring.activemq.user
    指定broker的用户.

8.8.3 jms

  • spring.jms.jndi-name
    指定Connection factory JNDI 名称.

  • spring.jms.listener.acknowledge-mode
    指定ack模式,默认自动ack.

  • spring.jms.listener.auto-startup
    是否启动时自动启动jms,默认为: true

  • spring.jms.listener.concurrency
    指定最小的并发消费者数量.

  • spring.jms.listener.max-concurrency
    指定最大的并发消费者数量.

  • spring.jms.pub-sub-domain
    是否使用默认的destination type来支持 publish/subscribe,默认: false

8.9 spring security

  • security.basic.authorize-mode
    要使用权限控制模式.

  • security.basic.enabled
    是否开启基本的鉴权,默认为true

  • security.basic.path
    需要鉴权的path,多个的话以逗号分隔,默认为[/**]

  • security.basic.realm
    HTTP basic realm 的名字,默认为Spring

  • security.enable-csrf
    是否开启cross-site request forgery校验,默认为false.

  • security.filter-order
    Security filter chain的order,默认为0

  • security.headers.cache
    是否开启http头部的cache控制,默认为false.

  • security.headers.content-type
    是否开启X-Content-Type-Options头部,默认为false.

  • security.headers.frame
    是否开启X-Frame-Options头部,默认为false.

  • security.headers.hsts
    指定HTTP Strict Transport Security (HSTS)模式(none, domain, all).

  • security.headers.xss
    是否开启cross-site scripting (XSS) 保护,默认为false.

  • security.ignored
    指定不鉴权的路径,多个的话以逗号分隔.

  • security.oauth2.client.access-token-uri
    指定获取access token的URI.

  • security.oauth2.client.access-token-validity-seconds
    指定access token失效时长.

  • security.oauth2.client.additional-information.[key]
    设定要添加的额外信息.

  • security.oauth2.client.authentication-scheme
    指定传输不记名令牌(bearer token)的方式(form, header, none,query),默认为header

  • security.oauth2.client.authorities
    指定授予客户端的权限.

  • security.oauth2.client.authorized-grant-types
    指定客户端允许的grant types.

  • security.oauth2.client.auto-approve-scopes
    对客户端自动授权的scope.

  • security.oauth2.client.client-authentication-scheme
    传输authentication credentials的方式(form, header, none, query),默认为header方式

  • security.oauth2.client.client-id
    指定OAuth2 client ID.

  • security.oauth2.client.client-secret
    指定OAuth2 client secret. 默认是一个随机的secret.

  • security.oauth2.client.grant-type
    指定获取资源的access token的授权类型.

  • security.oauth2.client.id
    指定应用的client ID.

  • security.oauth2.client.pre-established-redirect-uri
    服务端pre-established的跳转URI.

  • security.oauth2.client.refresh-token-validity-seconds
    指定refresh token的有效期.

  • security.oauth2.client.registered-redirect-uri
    指定客户端跳转URI,多个以逗号分隔.

  • security.oauth2.client.resource-ids
    指定客户端相关的资源id,多个以逗号分隔.

  • security.oauth2.client.scope
    client的scope

  • security.oauth2.client.token-name
    指定token的名称

  • security.oauth2.client.use-current-uri
    是否优先使用请求中URI,再使用pre-established的跳转URI. 默认为true

  • security.oauth2.client.user-authorization-uri
    用户跳转去获取access token的URI.

  • security.oauth2.resource.id
    指定resource的唯一标识.

  • security.oauth2.resource.jwt.key-uri
    JWT token的URI. 当key为公钥时,或者value不指定时指定.

  • security.oauth2.resource.jwt.key-value
    JWT token验证的value. 可以是对称加密或者PEMencoded RSA公钥. 可以使用URI作为value.

  • security.oauth2.resource.prefer-token-info
    是否使用token info,默认为true

  • security.oauth2.resource.service-id
    指定service ID,默认为resource.

  • security.oauth2.resource.token-info-uri
    token解码的URI.

  • security.oauth2.resource.token-type
    指定当使用userInfoUri时,发送的token类型.

  • security.oauth2.resource.user-info-uri
    指定user info的URI

  • security.oauth2.sso.filter-order
    如果没有显示提供WebSecurityConfigurerAdapter时指定的Filter order.

  • security.oauth2.sso.login-path
    跳转到SSO的登录路径默认为/login.

  • security.require-ssl
    是否对所有请求开启SSL,默认为false.

  • security.sessions
    指定Session的创建策略(always, never, if_required, stateless).

  • security.user.name
    指定默认的用户名,默认为user.

  • security.user.password
    默认的用户密码.

  • security.user.role
    默认用户的授权角色.

8.10 其他

8.10.1 aop

  • spring.aop.auto
    是否支持@EnableAspectJAutoProxy,默认为: true

  • spring.aop.proxy-target-class
    true为使用CGLIB代理,false为JDK代理,默认为false

8.10.2 application

  • spring.application.admin.enabled
    是否启用admin特性,默认为: false

  • spring.application.admin.jmx-name
    指定admin MBean的名称,默认为: org.springframework.boot:type=Admin,name=SpringApplication

8.10.3 autoconfig

  • spring.autoconfigure.exclude
    配置要排除的Auto-configuration classes.

8.10.4 batch

  • spring.batch.initializer.enabled
    是否在必要时创建batch表,默认为true

  • spring.batch.job.enabled
    是否在启动时开启batch job,默认为true

  • spring.batch.job.names
    指定启动时要执行的job的名称,逗号分隔,默认所有job都会被执行

  • spring.batch.schema
    指定要初始化的sql语句路径,默认:classpath:org/springframework/batch/core/schema-@@platform@@.sql)

  • spring.batch.table-prefix
    指定批量处理的表的前缀.

8.10.5 jmx

  • spring.jmx.default-domain
    指定JMX domain name.

  • spring.jmx.enabled
    是否暴露jmx,默认为true

  • spring.jmx.server
    指定MBeanServer bean name. 默认为: mbeanServer)

8.10.6 mail

  • spring.mail.default-encoding
    指定默认MimeMessage的编码,默认为: UTF-8

  • spring.mail.host
    指定SMTP server host.

  • spring.mail.jndi-name
    指定mail的jndi名称

  • spring.mail.password
    指定SMTP server登陆密码.

  • spring.mail.port
    指定SMTP server port.

  • spring.mail.properties
    指定JavaMail session属性.

  • spring.mail.protocol
    指定SMTP server使用的协议,默认为: smtp

  • spring.mail.test-connection
    指定是否在启动时测试邮件服务器连接,默认为false

  • spring.mail.username
    指定SMTP server的用户名.

8.10.7 sendgrid

  • spring.sendgrid.password
    指定SendGrid password.

  • spring.sendgrid.proxy.host
    指定SendGrid proxy host.

  • spring.sendgrid.proxy.port
    指定SendGrid proxy port.

  • spring.sendgrid.username
    指定SendGrid username.

8.10.8 social

  • spring.social.auto-connection-views
    是否开启连接状态的视图,默认为false

  • spring.social.facebook.app-id
    指定应用id

  • spring.social.facebook.app-secret
    指定应用密码

  • spring.social.linkedin.app-id
    指定应用id

  • spring.social.linkedin.app-secret
    指定应用密码

  • spring.social.twitter.app-id
    指定应用ID.

  • spring.social.twitter.app-secret
    指定应用密码

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一些 Spring Boot 面试时可能会涉及的重要知识点和面试建议: 1. 什么是 Spring BootSpring BootSpring 框架的一个子项目,它基于 Spring 框架,简化了 Spring 应用的配置和开发过程,使得开发者可以更加便捷地创建独立、生产级别的 Spring 应用。Spring Boot 提供了自动化配置、开箱即用的组件和快速启动的能力,使得开发者可以更加专注于业务逻辑的实现。 2. Spring Boot 有哪些优点? - 简化了 Spring 应用的配置和开发过程。 - 集成了众多常用的第三方库,可以快速地搭建项目。 - 提供了自动化配置和开箱即用的组件,使得开发者可以更加专注于业务逻辑的实现。 - 与 Spring Framework 完美集成,可以很方便地使用 Spring 的各种功能。 - 支持多种开发方式,包括传统的 WAR 包部署、嵌入式服务器部署、Docker 容器化部署等。 3. Spring Boot 的核心注解有哪些? - @SpringBootApplication:用于标记 Spring Boot 应用的主类,它包含了 @Configuration、@EnableAutoConfiguration 和 @ComponentScan 三个注解,可以简化应用的配置和启动过程。 - @Controller、@Service、@Repository、@Component:用于标记 Spring Bean,可以自动扫描并注册到 Spring 容器中。 - @Autowired、@Resource、@Inject:用于依赖注入,可以自动装配 Spring Bean。 4. Spring Boot 的配置文件有哪些? Spring Boot 支持多种配置文件格式,包括 properties、yml、json 等。其中,application.properties 或 application.yml 是 Spring Boot 默认的配置文件,它可以放在项目的 classpath 下,也可以通过指定 spring.config.location 属性来指定配置文件的路径。 5. Spring Boot 的自动配置原理是什么? Spring Boot 的自动配置基于条件注解和条件判断,它会根据应用的上下文环境和 classpath 中的依赖库来自动配置 Spring Bean。例如,当 classpath 中存在 HikariCP 库时,Spring Boot 会自动配置一个 HikariCP 数据源,而不需要手动配置。 6. Spring Boot 如何处理异常? Spring Boot 提供了统一的异常处理机制,可以通过 @ControllerAdvice 和 @ExceptionHandler 注解来处理应用中的异常。在异常处理类中,可以通过 @ExceptionHandler 注解和方法参数来定义需要处理的异常类型和异常处理逻辑。 7. Spring Boot 如何实现 AOP? Spring Boot 集成了 Spring Framework 的 AOP 功能,可以通过 @Aspect 和 @Around 注解来实现切面编程。在切面类中,可以定义需要拦截的方法和拦截逻辑,以实现日志记录、权限控制等功能。 8. Spring Boot 如何实现事务管理? Spring Boot 集成了 Spring Framework 的事务管理功能,可以通过 @Transactional 注解来实现事务控制。在需要进行事务控制的方法上添加 @Transactional 注解,即可开启事务。 9. Spring Boot 如何集成数据库? Spring Boot 支持多种数据库,包括 MySQL、Oracle、MongoDB 等,可以通过在 pom.xml 中添加相应的依赖库来实现数据库的集成。同时,Spring Boot 也提供了多种数据库访问方式,包括 JDBC、JPA、MyBatis 等,可以根据实际需求选择合适的方式。 10. Spring Boot 如何实现缓存? Spring Boot 集成了多种缓存框架,包括 Ehcache、Redis、Caffeine 等,可以通过在 pom.xml 中添加相应的依赖库来实现缓存功能。同时,Spring Boot 也提供了多种缓存注解,包括 @Cacheable、@CachePut、@CacheEvict 等,可以方便地实现缓存功能。 面试建议: - 对于 Spring Boot 的基本原理和使用方法要有深入了解,并能够熟练使用 Spring Boot 搭建项目。 - 对于 Spring Boot 中常用的注解和配置文件要熟练掌握。 - 对于 Spring Boot 中的高级功能(如自动配置、AOP、事务管理、缓存等)要有一定的了解,并能够根据实际需求进行应用。 - 在面试中要注意表达清楚自己的观点和思路,可以通过实际项目经验来证明自己的能力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值