springboot加载配制文件_写给自己看

Spring Boot默认的配置文件名称为application.properties
寻找顺序如下:
a.当前目录下的/config子目录
b.当前目录
c.一个classpath下的/config包
d.classpath根路径(root)

列如
 application.properties内容如下
ftm.redis.addressList=10.17.5.24:6379,10.17.5.24:6380
ftm.redis.minIdle=10
ftm.redis.maxIdle=100
ftm.redis.maxTotal=8
ftm.redis.maxWaitMillis=1000
-------------------------------------------------------------------------
对应的java类应该有这两个注解
@Component
@ConfigurationProperties(prefix = "ftm.redis")

 

package com.liangbo.xing.flexibletranscation.config.redis;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "ftm.redis")
public class RedisProperties {
    private List<String> addressList;
    private int          minIdle;
    private int          maxIdle;
    private int          maxTotal;
    private long         maxWaitMillis;
    /**
     * Getter method for property <tt>addressList</tt>.
     *
     * @return property value of addressList
     */
    public List<String> getAddressList() {
        return addressList;
    }

    /**
     * Setter method for property <tt>addressList</tt>.
     *
     * @param addressList value to be assigned to property addressList
     */
    public void setAddressList(List<String> addressList) {
        this.addressList = addressList;
    }

    /**
     * Getter method for property <tt>minIdle</tt>.
     *
     * @return property value of minIdle
     */
    public int getMinIdle() {
        return minIdle;
    }

    /**
     * Setter method for property <tt>minIdle</tt>.
     *
     * @param minIdle value to be assigned to property minIdle
     */
    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }

    /**
     * Getter method for property <tt>maxIdle</tt>.
     *
     * @return property value of maxIdle
     */
    public int getMaxIdle() {
        return maxIdle;
    }

    /**
     * Setter method for property <tt>maxIdle</tt>.
     *
     * @param maxIdle value to be assigned to property maxIdle
     */
    public void setMaxIdle(int maxIdle) {
        this.maxIdle = maxIdle;
    }

    /**
     * Getter method for property <tt>maxTotal</tt>.
     *
     * @return property value of maxTotal
     */
    public int getMaxTotal() {
        return maxTotal;
    }

    /**
     * Setter method for property <tt>maxTotal</tt>.
     *
     * @param maxTotal value to be assigned to property maxTotal
     */
    public void setMaxTotal(int maxTotal) {
        this.maxTotal = maxTotal;
    }

    /**
     * Getter method for property <tt>maxWaitMillis</tt>.
     *
     * @return property value of maxWaitMillis
     */
    public long getMaxWaitMillis() {
        return maxWaitMillis;
    }

    /**
     * Setter method for property <tt>maxWaitMillis</tt>.
     *
     * @param maxWaitMillis value to be assigned to property maxWaitMillis
     */
    public void setMaxWaitMillis(long maxWaitMillis) {
        this.maxWaitMillis = maxWaitMillis;
    }
}

猜你喜欢

转载自blog.csdn.net/maqingbin8888/article/details/81389471