springmvc中如何从配置文件中读取信息

如题所述

1、第一步,先新建一个.properties文件,
app.properties里面内容
admin=admin
test=test
2、第二步,新建一个xml文件,在applicationContext.xml,
<!-- 用来解析Java Properties属性文件值(注意class指定的类)-->
<bean id="placeholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:app.properties</value>
</list>
</property>
</bean>
<!-- 把properties里面的信息读进来: -->

<bean id="report" class="java.lang.String">
<constructor-arg value="${admin}"/>
</bean>
温馨提示:答案为网友推荐,仅供参考
相似回答