您的位置:首页 > 编程语言 > Java开发

Spring注入属性值 以及context-param参数介绍

2017-06-05 09:45 246 查看
1.在applicationContext.xml文件下配置:

<bean id="appProperty"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<array>
<value>classpath:app.properties</value>
</array>
</property>
</bean>


2.在需要注入属性处使用@Value注解:

比如:@Value(“${jdbc.username}”)

public String username;

3.web.xml文件中的
<context-param></context-param>
会被转化为键值对存在servletContext中,这个过程是在所有servlet启动之前执行的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息