我使用下面的代码来读取文件,我可以使用env.properties
注释(注入)读取@Value
中定义的值。
有没有办法在不使用@value
(注入)的情况下在方法中获取这些值?
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:env.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="ignoreResourceNotFound" value="true" />
</bean>
答案 0 :(得分:1)
您也可以在属性bean中自动装配:
<!-- creates a java.util.Properties instance with values loaded from the supplied location -->
<util:properties id="properties" location="classpath:/environment.properties"/>
或者在你的方法中做一个getBean()
。
但坚持@value
,它光滑,简单,易于测试。