SpringBoot中静态类使用配置文件
经常遇到读取为NULL的情况,现在我就告诉大家。
----------------------------------application-jwt.properties------------------------
ccb.jwt.toke.secret=eyJhbGciOiJIUzI1NiJ9 ccb.jwt.toke.issuer=BJxingjingzhida ccb.jwt.toke.userno=userId ccb.jwt.toke.date=1
----------------------------------JwtProConfig,java---------------------------------
package com.bcc.common.config; import javax.annotation.PostConstruct; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @Configuration //@Component @PropertySource({"classpath:application-jwt.properties"}) @ConfigurationProperties(prefix = "ccb.jwt.toke") public class JwtProConfig { public static String TOKEN_SECRET; public static String ISSUER; public static String USERNO; public static Long DATE;// = 1L; //10秒钟 public String secret; public String issuer; public String userno; public Long date; @PostConstruct public void JwtProConfigValue() { TOKEN_SECRET = this.secret; ISSUER = this.issuer; USERNO = this.userno; //DATE = Long.valueOf(this.date); DATE = this.date; } public String getSecret() { return secret; } public void setSecret(String secret) { this.secret = secret; } public String getIssuer() { return issuer; } public void setIssuer(String issuer) { this.issuer = issuer; } public String getUserno() { return userno; } public void setUserno(String userno) { this.userno = userno; } public Long getDate() { return date; } public void setDate(Long date) { this.date = date; } }
----------------------------------最后直 接类.静态属性 -------------------------------