SpringBoot properties 屬性綁定,總顯示 null

主要問題:未寫 set 方法。

application.properties

jwt.token.secretKey=mwl_secret
jwt.token.expireLength=1800000

JWTPovider

@Component
@ConfigurationProperties(prefix = "jwt.token")
 // 必須寫 set 方法 ,即使是 屬性是 public 
public class JWTokenProvider {
    public String secretKey;
    public String expireLength;
    
    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }
    public void setExpireLength(String expireLength) {
        this.expireLength = expireLength;
    }
}

pom.xml

<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-configuration-processor</artifactId>
		<optional>true</optional>
</dependency>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章