我的spring启动应用程序中有嵌套属性。例如:
topics:
target:
abc_1:
12345678:
key: value_1
default:
key: value_1
@Value
在我的课堂上,像这样:
@Value("${topics.target.abc_1.12345678.key}")
private String key;
但我在启动应用程序时遇到以下异常。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '***': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'topics.target.abc_1.12345678.key' in value "${topics.target.abc_1.12345678.key}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:378)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1341)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:393)
但令人惊讶的是,当我尝试加载
topics.target.abc_1.default.key
我确信在非嵌套结构中,带有数字值的键不会有任何问题。