properties文件
1.properties文件以.properties为后缀
2.一行写一个参数的值(key-value一行一个).如:redis.host=127.0.0.1
3.字符串不用加“”,是以行来读取内容的,所以多一个空格都会得不到你想要的结果
redis.properties
# Redis settings redis.host=127.0.0.1 redis.port=6379 redis.pass= redis.maxIdle=300 redis.maxTotal=600 redis.maxWaitMillis=1000 redis.testOnBorrow=true
XML读取properties文件内容
<context:property-placeholder location="classpath:redis.properties" /> //location指明properties文件路径(classpath以类路径作为参考) <bean id="poolConfig" class="redis.clients.jedis.JedisPoolConfig"> <property name="maxIdle" value="${redis.maxIdle}" /> //${redis.maxIdle},读取redis.properties里的redis.maxIdle的值 <property name="maxTotal" value="${redis.maxTotal}" /> <property name="maxWaitMillis" value="${redis.maxWaitMillis}" /> <property name="testOnBorrow" value="${redis.testOnBorrow}" /> </bean>
代码读取properties文件内容
public class ConfigUtils { public static String host = null; static { ResourceBundle res = ResourceBundle.getBundle("redis");//读取redis.properties文件 WX_SRC = res.getString("redis.host");//读取redis.properties里的redis.host的值 } }