@Component 生成組建
@ConfigurationProperties(prefix="redis") 讀寫redis配置檔案
application.properties配置檔案
#redis redis.host=127.0.0.1 redis.port=6379 redis.timeout=3 redis.password= redis.poolMaxTotal=10 redis.poolMaxIdle=10 redis.poolMaxWait=3
package com.java.seckill.redis; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @Component @ConfigurationProperties(prefix="redis") @AllArgsConstructor @NoArgsConstructor @Data public class RedisConfig { private String host; private Integer port; private Integer timeout; private String password; private Integer poolMaxTotal; private Integer poolMaxIdle; private Integer poolMaxWait; }