0

我正在使用下面的代码来读取文件,我可以读取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>
4

1 回答 1

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,它的流畅、简单且易于测试。

于 2013-09-19T07:15:13.147 回答