Spring MVC 经过@Value注解读取.properties配置内容

第一步:spring

在applicationContext.xml配置:app

<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath:/config/*.properties</value>
            </list>
        </property>
    </bean>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
        <property name="properties" ref="configProperties" />
    </bean>

第二步:spa

创建配置文件内容:code

例如:userPageSize=5xml

第三步:字符串

在Controller中使用注解得到配置项内容:io

@Value("#{configProperties['userPageSize']}")
private String userPageSize;

第四步:class

后面的代码就可使用userPageSize这个私有变量了,这个字符串的值就是咱们配置文件中配置的5.变量

相关文章
相关标签/搜索