Issue
I want to define a class to read the spring boot application.properties, this is the model class:
package com.dolphin.soa.post.common.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "dolphin.redis")
@ConfigurationPropertiesScan
public class CruiseRedisKeysConfig {
private String userSubArticleKey;
}
and this is the start up class:
@EnableConfigurationProperties(CruiseRedisKeysConfig.class)
public class AppStarter {}
but when I using this configuration, the userSubArticleKey value was null. why could not read the application.properties value? what should I do to fixed this problem? and this is the application.properties:
dolphin.redis.user.sub.article.key=cruise:user:sub:article:
Solution
The Java property userSubArticleKey
will be userSubArticleKey
or user-sub-article-key
in your properties file:
application.properties
:
dolphin.redis.userSubArticleKey=cruise:user:sub:article:
user.sub.article.key
means the property key
in nested object reachable via article
, via nested sub
, via nested user
.
Answered By - knittl
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.