inv*_*ant 5 java spring spring-4
我正在使用 spring 加载属性文件
<bean id="appProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:/sample.properties" />
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
当我使用
@Value("${testkey}") 它的工作正常。
但是当我尝试使用 env 时
@Resource
private Environment environment;
environment.getProperty("testkey") // returning null
Run Code Online (Sandbox Code Playgroud)
APropertyPlaceholderConfigurer不会将其属性添加locations到Environment. 通过 Java 配置,您可以使用@PropertySource它来做到这一点。
| 归档时间: |
|
| 查看次数: |
15762 次 |
| 最近记录: |