1. 程式人生 > >springboot 讀取yml檔案模板

springboot 讀取yml檔案模板

config.properties

redis:
  arrayProps: 1,2,3,4,5
  password: 123456
  redisHostList:
  - 192.168.1.1:6379
  - 192.168.1.2:6379
  redisNameList:
  - level_0
  - level_1
  jedis:
    max-idle: 5
    maxactive: 100
    maxwait: 5000
  map: {time: devname,time2: devname} 
@Data
@ConfigurationProperties
(prefix = "redis") @PropertySource(value = "classpath:config.properties") public class MyJedisPoolConfig { @Autowired private Environment env; @Value("${redis.jedis.maxactive}") private int maxActive; @Value("${redis.jedis.max-idle}") private int maxIdle; @Value("${redis.jedis.maxwait}"
) private long maxWait; @Value("${redis.password}") private String password; private String[] arrayProps; private List<String> redisNameList = new ArrayList<>(); private List<String> redisHostList = new ArrayList<>(); private Map<String, String> map =
new HashMap<>(); ... System.out.println(env.getProperty("")); }

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html