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

来源:互联网 发布:物联网与人工智能 编辑:程序博客网 时间:2024/06/03 21:07

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启动之前执行的。

阅读全文
0 0