上下文:属性持有者与属性占位符配置器



以下 2 种情况下如何使用@Value?

案例 1:我有一个属性占位符配置器 bean 定义如下

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <value>file:#{ systemProperties['user.home']}/myconf/settings.properties</value>
    </property>
</bean>

案例 2:我没有定义 bean,但我在上下文中声明了属性占位符,如下所示

<context:property-placeholder 
     location="file:#{ systemProperties['user.home']}/myconf/settings.properties"  />

在这两种情况下,您都会使用 like

@Value(value="${key.in.file}")
private String myVar;

最新更新