Describe the bug
I try to load application properties directly from the jdbc backend repository. After some hard work, my application runs up finally, but when use @ConfigurationProperties
none values are binded, instead @Value
works ok.
Sample
bootstrap.yml
spring:
application:
name: @project.artifactId@
profiles:
active: jdbc,debug
cloud:
config:
server:
bootstrap: true
jdbc:
# just for test sql
sql: SELECT `property_key`, `property_value` from system_property where 1 = 1 or property_key in (?, ?, ?)
datasource:
username: root
password: password
url: jdbc:mysql://xxxxx
hikari:
driver-class-name: com.mysql.cj.jdbc.Driver
spring.factories
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\
org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration
component
@Component
@ConfigurationProperties(prefix = "system")
@Getter
@Setter
public class BasePropertyComponent implements InitializingBean {
private int threshold;
@Value("${system.threshold}")
private int thresholdIntvalue;
@Override
public void afterPropertiesSet() {
// threshold is not binded
System.out.println(threshold);
// @Value("${system.threshold}") is binded
System.out.println(thresholdIntvalue);
}
}
Comment From: yanshenxian
😢 Sorry, I've made a mistake. The problem is none existed because I stored wrong property value in database. This issue can be closed now~