我们可以让Spring读取properties文件中的key/value,然后使用其中的值。
①设置读取properties
在Spring配置文件中加入如下标签:指定要读取的文件的路径。
<context:property-placeholder location="classpath:filename.properties">
其中的classpath表示类加载路径下。
我们也会用到如下写法:classpath:*.properties 其中的 * 表示文件名任意。
注意:context命名空间的引入是否正确
②使用配置文件中的值
在我们需要使用的时候可以使用${key}来表示具体的值。注意要再value属性中使用才可以。例如:
<property name="propertyName" value="${key}"/>