SpringBoot常用属性配置

SpringBoot 2.x:https://github.com/spring-projects/spring-boot/blob/2.0.x/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

1、详见:http://docs.spring.io/spring-boot/docs/1.5.2.RELEASE/reference/htmlsingle/#common-application-properties

2、上面文件的另外一个版本:https://github.com/spring-projects/spring-boot/blob/v1.5.2.RELEASE/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

官方文档上是这么说明这个属性列表的:

注:属性可以来自classpath下的其他jar文件中, 所以你不应该把它当成详尽的列表。 定义你自己的属性也是相当合法的。

注:示例文件只是一个指导。 不要拷贝/粘贴整个内容到你的应用, 而是只提取你需要的属性

3、上面这个链接只是列举的部分常用的属性项,完整的配置在:spring-boot-autoconfigure-xxx.jar里的xxx模块下的XXProperties.java里。

完整的列表:https://github.com/spring-projects/spring-boot/tree/v1.5.2.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure

这里拿redis举例:

https://github.com/spring-projects/spring-boot/blob/v1.5.2.RELEASE/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/redis/RedisProperties.java

这个对象里的属性就为可以配置的所有的属性。

摘取上面那个RedisProperties.java文件里的部分代码:

package org.springframework.boot.autoconfigure.data.redis;

import java.util.List;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * Configuration properties for Redis.
 *
 * @author Dave Syer
 * @author Christoph Strobl
 * @author Eddú Meléndez
 * @author Marco Aust
 */
@ConfigurationProperties(prefix = "spring.redis")
public class RedisProperties {

    /**
     * Database index used by the connection factory.
     */
    private int database = 0;

    /**
     * Redis url, which will overrule host, port and password if set.
     */
    private String url;

    /**
     * Redis server host.
     */
    private String host = "localhost";

    /**
     * Login password of the redis server.
     */
    private String password;

    /**
     * Redis server port.
     */
    private int port = 6379;

    /**
     * Enable SSL.
     */
    private boolean ssl;

    /**
     * Connection timeout in milliseconds.
     */
    private int timeout;

        //...........................
}
原文地址:https://www.cnblogs.com/yangzhilong/p/6538195.html