在Spring 中经常将一些配置项写在properties文件中,例如DB 的配置等。在Spring 中一般有以下两种加载properties文件的方式:基于xml方式和基于注解方式`
一. 基于XML方式配置
Spring中有个 context:property-placeholder location=”“/标签,可以用来加载properties配置文件,location是配置文件的路径,
- 我们现在在工程目录的src下新建一个redis.properties文件,里面写上上面redis的配置:
#redis中心
redis.host=10.75.202.11
redis.port=6379
redis.password=123456
redis.maxIdle=100
redis.maxActive=300
redis.maxWait=1000
redis.timeout=100000
# 不需要加入缓存的类 targetNames=xxxRecordManager,xxxSetRecordManager,xxxStatisticsIdentificationManager
# 不需要缓存的方法
methodNames=
#设置缓存失效时间
com.service.impl.xxxRecordManager= 60 com.service.impl.xxxSetRecordManager= 60 defaultCacheExpireTime=3600
fep.local.cache.capacity =10000
2.现在只需要在beans.xml中做如下修改即可(这个只限于xml的方式,即在beans.xml中用${key}获取properties文件中的值value。):
<!-- 引入properties配置文件 -->
<