Java游戏服务器开发之二十三--将xml-cfg和redis的配置内容加到properties中.md

Posted by lizhao on 07-09,2019

Java游戏服务器开发之二十三--将xml-cfg和redis的配置内容加到properties中

之前将xml-cfg和redis的工具类都写好了,但是里面的参数都是写在程序里面的,这一篇的话就是讲这2个的配置文件写到properties中,不需要编译程序就可以直接修改配置了

xml-cfg

所需要的参数

#* @param cfgPackageName   转换出来的类所在的包名
#* @param cfgPrefix        转换出来类的前缀
#* @param catalogDir       所有配置的清单文件 所在的文件夹
#* @param catalogFile      所有配置的清单文件
#* @param catalogMainNode  清单文件的标签
#* @param catalogAttribute 清单文件的标签名称
#* @param xmlFileDir       xml文件对应的路径

设置参数的值

xml.cfg.cfgPackageName=com.lizhaoblog.server.biz.entity.cfg.
xml.cfg.cfgPrefix=ConfigDataArrCfg
xml.cfg.catalogDir=/cfg/
xml.cfg.catalogFile=dataConfig.xml
xml.cfg.catalogMainNode=/config/file
xml.cfg.catalogAttribute=name
xml.cfg.xmlFileDir=/cfg/data-static-config/

文件路径

resources--》properties--》xml-cfg-config-dev.properties

redis配置

所需要的参数

#   * @param poolConfig    连接池设置
    #JedisPoolConfig poolConfig = new JedisPoolConfig();
    #//设置最大连接数(100个足够用了,没必要设置太大)
    #poolConfig.setMaxTotal(100);
    #//最大空闲连接数
    #poolConfig.setMaxIdle(10);
    #//获取Jedis连接的最大等待时间(50秒)
    #poolConfig.setMaxWaitMillis(50 * 1000);
    #//在获取Jedis连接时,自动检验连接是否可用
    #poolConfig.setTestOnBorrow(false);
    #//在将连接放回池中前,自动检验连接是否有效
    #poolConfig.setTestOnReturn(true);
    #//自动测试池中的空闲连接是否都是可用连接
    #poolConfig.setTestWhileIdle(true);
#   * @param host          主机
#   * @param port          端口
#   * @param timeout       超时
#   * @param password      密码
#   * @param databaseIndex 数据库

设置参数的值

redis.host=127.0.0.1
redis.port=6379
redis.timeout=2000
redis.password=admin123
redis.databaseIndex=1
redis.poolConfig.maxTotal=100
redis.poolConfig.MaxIdle=10
redis.poolConfig.MaxWaitMillis=50000
redis.poolConfig.testOnBorrow=false
redis.poolConfig.testOnReturn=true
redis.poolConfig.testWhileIdle=true

文件路径

resources--》properties--》redis-config-dev.properties

在ServerConfig中添加参数

添加内容

// xml cfg
@Value("#{cfgProps['xml.cfg.cfgPackageName']}")
private String cfgPackageName;
@Value("#{cfgProps['xml.cfg.cfgPrefix']}")
private String cfgPrefix;
@Value("#{cfgProps['xml.cfg.catalogDir']}")
private String catalogDir;
@Value("#{cfgProps['xml.cfg.catalogFile']}")
private String catalogFile;
@Value("#{cfgProps['xml.cfg.catalogMainNode']}")
private String catalogMainNode;
@Value("#{cfgProps['xml.cfg.catalogAttribute']}")
private String catalogAttribute;
@Value("#{cfgProps['xml.cfg.xmlFileDir']}")
private String xmlFileDir;

// Redis config
@Value("#{cfgProps['redis.host']}")
private String redisHost;
@Value("#{cfgProps['redis.port']}")
private Integer redisPort;
@Value("#{cfgProps['redis.timeout']}")
private Integer redisTimeout;
@Value("#{cfgProps['redis.password']}")
private String redisPassword;
@Value("#{cfgProps['redis.databaseIndex']}")
private Integer redisDatabaseIndex;

@Value("#{cfgProps['redis.poolConfig.maxTotal']}")
private Integer redisPoolConfigMaxTotal;
@Value("#{cfgProps['redis.poolConfig.MaxIdle']}")
private Integer redisPoolConfigMaxIdle;
@Value("#{cfgProps['redis.poolConfig.MaxWaitMillis']}")
private Long redisPoolConfigMaxWaitMillis;
@Value("#{cfgProps['redis.poolConfig.testOnBorrow']}")
private Boolean redisPoolConfigTestOnBorrow;
@Value("#{cfgProps['redis.poolConfig.testOnReturn']}")
private Boolean redisPoolConfigTestOnReturn;
@Value("#{cfgProps['redis.poolConfig.testWhileIdle']}")
private Boolean redisPoolConfigTestWhileIdle;

添加get和set方法

在BasicServerImpl中初始化xml-cfg和redis

 private void init() throws XmlConfigReadException, ServerErrException, RedisException {
ServerConfig serverConfig = ServerConfig.getInstance();

// 初始化xml-cfg工具类
logger.info("初始化xml-cfg工具类  开始");
serverConfig.printXmlCfgInfo();
ConfigDataManager.getInstance()
        .loadXml(serverConfig.getCfgPackageName(), serverConfig.getCfgPrefix(), serverConfig.getCatalogDir(),
                serverConfig.getCatalogFile(), serverConfig.getCatalogMainNode(),
                serverConfig.getCatalogAttribute(), serverConfig.getXmlFileDir());
logger.info("初始化xml-cfg工具类  结束");

// 初始化redis工具类
logger.info("redis工具类  开始");
serverConfig.printRedisInfo();
JedisPoolConfig poolConfig = new JedisPoolConfig();
//设置最大连接数(100个足够用了,没必要设置太大)
poolConfig.setMaxTotal(serverConfig.getRedisPoolConfigMaxTotal());
//最大空闲连接数
poolConfig.setMaxIdle(serverConfig.getRedisPoolConfigMaxIdle());
//获取Jedis连接的最大等待时间(50秒)
poolConfig.setMaxWaitMillis(serverConfig.getRedisPoolConfigMaxWaitMillis());
//在获取Jedis连接时,自动检验连接是否可用
poolConfig.setTestOnBorrow(serverConfig.getRedisPoolConfigTestOnBorrow());
//在将连接放回池中前,自动检验连接是否有效
poolConfig.setTestOnReturn(serverConfig.getRedisPoolConfigTestOnReturn());
//自动测试池中的空闲连接是否都是可用连接
poolConfig.setTestWhileIdle(serverConfig.getRedisPoolConfigTestWhileIdle());
Redis.getInstance().createJedisPool(poolConfig, serverConfig.getRedisHost(), serverConfig.getRedisPort(),
        serverConfig.getRedisTimeout(), serverConfig.getRedisPassword(), serverConfig.getRedisDatabaseIndex());
// 测试线程池是否已经建立完毕
Redis.getInstance().testConnection();
logger.info("redis工具类  结束");

// 启动通讯服务
logger.info("启动通讯服务  开始");
Integer port = serverConfig.getPort();
String channelType = serverConfig.getChannelType();
ChannelInitializer<SocketChannel> tcpServerStringInitializer = (ChannelInitializer<SocketChannel>) serverConfig
        .getApplicationContext().getBean("tcpServerStringInitializer");
acceptorChannel = ServerChannelFactory.createAcceptorChannel(port, channelType, tcpServerStringInitializer);
logger.info("启动通讯服务  结束");

}

看下具体代码

改动内容

Redis.java                      添加测试连接池
BasicServerImpl.java            初始化初始化xml-cfg和redis
ServerConfig.java               添加变量
redis-config-dev.properties     redis的配置存放位置
xml-cfg-config-dev.properties   xml-cfg的配置存放位置
ApplicationContext.xml          将redis的配置和xml-cfg的配置加到spring中        

具体代码

Redis.java 添加测试连接池

/*
 * Copyright (C), 2015-2018
 * FileName: Redis
 * Author:   zhao
 * Date:     2018/8/4 10:30
 * Description: Redis工具
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.lizhaoblog.base.redis;

import com.lizhaoblog.base.exception.RedisException;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Tuple;

/**
 * 〈一句话功能简述〉<br>
 * 〈Redis工具,从<<Java游戏服务器开发>>一书中获取〉
 * <具体简单入门可以查看:https://blog.csdn.net/cmqwan/article/details/81481522>
 *
 * @author zhao
 * @date 2018/8/4 10:30
 * @since 1.0.1
 */
public class Redis {
  private static Redis instance;
  private static final Logger logger = LoggerFactory.getLogger(Redis.class);

  private JedisPool pool = null;

  public static Redis getInstance() {
    if (instance == null) {
      instance = new Redis();
    }
    return instance;
  }

  /**
   * 创建一个redis连接池
   *
   * @param poolConfig    连接池设置
   * @param host          主机
   * @param port          端口
   * @param timeout       超时
   * @param password      密码
   * @param databaseIndex 数据库
   */
  public void createJedisPool(final GenericObjectPoolConfig poolConfig, final String host, int port, int timeout,
          final String password, final int databaseIndex) {
    pool = new JedisPool(poolConfig, host, port, timeout, password, databaseIndex);
  }

  /**
   * 获取Jedis对象
   *
   * @return Jedis
   */
  public synchronized Jedis getJedis() {
    Jedis jedis = null;
    if (pool != null) {
      if (jedis == null) {
        try {
          jedis = pool.getResource();
        } catch (Exception e) {
          logger.debug("Jedis getJedis find error", e);
        }
      }
    }
    return jedis;
  }

  public void testConnection() throws RedisException {
    Jedis jedis = null;
    if (pool != null) {
      if (jedis == null) {
        try {
          jedis = pool.getResource();
        } catch (Exception e) {
          throw new RedisException("pool.getResource() find error");
        }
      }
    }
    jedis.close();
  }
...
    
}

BasicServerImpl.java 初始化初始化xml-cfg和redis

/*
 * Copyright (C), 2015-2018
 * FileName: BasicServerImpl
 * Author:   zhao
 * Date:     2018/6/20 20:23
 * Description: BasicServerImpl
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.lizhaoblog.server.core;

import com.lizhaoblog.base.exception.RedisException;
import com.lizhaoblog.base.exception.ServerErrException;
import com.lizhaoblog.base.exception.XmlConfigReadException;
import com.lizhaoblog.base.factory.ServerChannelFactory;
import com.lizhaoblog.base.network.IServer;
import com.lizhaoblog.base.redis.Redis;
import com.lizhaoblog.base.xml.ConfigDataManager;
import com.lizhaoblog.server.core.listener.NetworkListener;
import com.lizhaoblog.server.pojo.ServerConfig;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import redis.clients.jedis.JedisPoolConfig;

/**
 * 〈一句话功能简述〉<br>
 * 〈BasicServerImpl〉
 *
 * @author zhao
 * @date 2018/6/20 20:23
 * @since 1.0.0
 */
@Component
public class BasicServerImpl implements IServer {
  private Channel acceptorChannel;
  private static final Logger logger = LoggerFactory.getLogger(NetworkListener.class);

  @Override
  public void start() {
    try {
      init();
      ServerConfig.getInstance().printServerInfo();
      acceptorChannel.closeFuture().sync();
    } catch (XmlConfigReadException | RedisException | ServerErrException | InterruptedException e) {
      logger.debug("服务启动失败,程序即将退出", e);
      stop();
      System.exit(0);
    }
  }

  private void init() throws XmlConfigReadException, ServerErrException, RedisException {
    ServerConfig serverConfig = ServerConfig.getInstance();

    // 初始化xml-cfg工具类
    logger.info("初始化xml-cfg工具类  开始");
    serverConfig.printXmlCfgInfo();
    ConfigDataManager.getInstance()
            .loadXml(serverConfig.getCfgPackageName(), serverConfig.getCfgPrefix(), serverConfig.getCatalogDir(),
                    serverConfig.getCatalogFile(), serverConfig.getCatalogMainNode(),
                    serverConfig.getCatalogAttribute(), serverConfig.getXmlFileDir());
    logger.info("初始化xml-cfg工具类  结束");

    // 初始化redis工具类
    logger.info("redis工具类  开始");
    serverConfig.printRedisInfo();
    JedisPoolConfig poolConfig = new JedisPoolConfig();
    //设置最大连接数(100个足够用了,没必要设置太大)
    poolConfig.setMaxTotal(serverConfig.getRedisPoolConfigMaxTotal());
    //最大空闲连接数
    poolConfig.setMaxIdle(serverConfig.getRedisPoolConfigMaxIdle());
    //获取Jedis连接的最大等待时间(50秒)
    poolConfig.setMaxWaitMillis(serverConfig.getRedisPoolConfigMaxWaitMillis());
    //在获取Jedis连接时,自动检验连接是否可用
    poolConfig.setTestOnBorrow(serverConfig.getRedisPoolConfigTestOnBorrow());
    //在将连接放回池中前,自动检验连接是否有效
    poolConfig.setTestOnReturn(serverConfig.getRedisPoolConfigTestOnReturn());
    //自动测试池中的空闲连接是否都是可用连接
    poolConfig.setTestWhileIdle(serverConfig.getRedisPoolConfigTestWhileIdle());
    Redis.getInstance().createJedisPool(poolConfig, serverConfig.getRedisHost(), serverConfig.getRedisPort(),
            serverConfig.getRedisTimeout(), serverConfig.getRedisPassword(), serverConfig.getRedisDatabaseIndex());
    // 测试线程池是否已经建立完毕
    Redis.getInstance().testConnection();
    logger.info("redis工具类  结束");

    // 启动通讯服务
    logger.info("启动通讯服务  开始");
    Integer port = serverConfig.getPort();
    String channelType = serverConfig.getChannelType();
    ChannelInitializer<SocketChannel> tcpServerStringInitializer = (ChannelInitializer<SocketChannel>) serverConfig
            .getApplicationContext().getBean("tcpServerStringInitializer");
    acceptorChannel = ServerChannelFactory.createAcceptorChannel(port, channelType, tcpServerStringInitializer);
    logger.info("启动通讯服务  结束");

  }

  @Override
  public void stop() {
    if (acceptorChannel != null) {
      acceptorChannel.close().addListener(ChannelFutureListener.CLOSE);
    }
  }

  @Override
  public void restart() throws Exception {
    stop();
    start();
  }
}

ServerConfig.java 添加变量

/*
 * Copyright (C), 2015-2018
 * FileName: ServerConfig
 * Author:   zhao
 * Date:     2018/6/12 11:16
 * Description: 服务的配置内容
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.lizhaoblog.server.pojo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 〈一句话功能简述〉<br>
 * 〈服务的配置内容〉
 *
 * @author zhao
 * @date 2018/6/12 11:16
 * @since 1.0.0
 */
@Component
@Scope("singleton")
public class ServerConfig {
  private static final Logger logger = LoggerFactory.getLogger(ServerConfig.class);

  @Value("#{cfgProps['port']}")
  private Integer port;
  @Value("#{cfgProps['channelType']}")
  private String channelType;
  @Value("#{cfgProps['protocolType']}")
  private String protocolType;
  @Value("#{cfgProps['messageType']}")
  private String messageType;

  // xml cfg
  @Value("#{cfgProps['xml.cfg.cfgPackageName']}")
  private String cfgPackageName;
  @Value("#{cfgProps['xml.cfg.cfgPrefix']}")
  private String cfgPrefix;
  @Value("#{cfgProps['xml.cfg.catalogDir']}")
  private String catalogDir;
  @Value("#{cfgProps['xml.cfg.catalogFile']}")
  private String catalogFile;
  @Value("#{cfgProps['xml.cfg.catalogMainNode']}")
  private String catalogMainNode;
  @Value("#{cfgProps['xml.cfg.catalogAttribute']}")
  private String catalogAttribute;
  @Value("#{cfgProps['xml.cfg.xmlFileDir']}")
  private String xmlFileDir;

  // Redis config
  @Value("#{cfgProps['redis.host']}")
  private String redisHost;
  @Value("#{cfgProps['redis.port']}")
  private Integer redisPort;
  @Value("#{cfgProps['redis.timeout']}")
  private Integer redisTimeout;
  @Value("#{cfgProps['redis.password']}")
  private String redisPassword;
  @Value("#{cfgProps['redis.databaseIndex']}")
  private Integer redisDatabaseIndex;

  @Value("#{cfgProps['redis.poolConfig.maxTotal']}")
  private Integer redisPoolConfigMaxTotal;
  @Value("#{cfgProps['redis.poolConfig.MaxIdle']}")
  private Integer redisPoolConfigMaxIdle;
  @Value("#{cfgProps['redis.poolConfig.MaxWaitMillis']}")
  private Long redisPoolConfigMaxWaitMillis;
  @Value("#{cfgProps['redis.poolConfig.testOnBorrow']}")
  private Boolean redisPoolConfigTestOnBorrow;
  @Value("#{cfgProps['redis.poolConfig.testOnReturn']}")
  private Boolean redisPoolConfigTestOnReturn;
  @Value("#{cfgProps['redis.poolConfig.testWhileIdle']}")
  private Boolean redisPoolConfigTestWhileIdle;

  private ApplicationContext applicationContext;

  private static ServerConfig instance = null;

  private ServerConfig() {
  }

  public static ServerConfig getInstance() {
    if (instance == null) {
      instance = new ServerConfig();
      logger.debug("ServerConfig is not init by spring");
    }
    return instance;
  }

  @PostConstruct
  public void init() {
    instance = this;
  }

  public void printServerInfo() {
    logger.info("**************Server INFO******************");
    logger.info("protocolType  : " + protocolType);
    logger.info("port          : " + port);
    logger.info("channelType   : " + channelType);
    logger.info("messageType   : " + messageType);
    logger.info("**************Server INFO******************");
  }
  public void printXmlCfgInfo() {
    logger.info("**************Xml Cfg INFO******************");
    logger.info("cfgPackageName     : " + cfgPackageName);
    logger.info("cfgPrefix          : " + cfgPrefix);
    logger.info("catalogDir         : " + catalogDir);
    logger.info("catalogFile        : " + catalogFile);
    logger.info("catalogMainNode    : " + catalogMainNode);
    logger.info("catalogAttribute   : " + catalogAttribute);
    logger.info("xmlFileDir         : " + xmlFileDir);
    logger.info("**************Xml Cfg INFO******************");
  }
  // Redis config
  public void printRedisInfo() {
    logger.info("**************Redis INFO******************");
    logger.info("redisHost                      : " + redisHost);
    logger.info("redisPort                      : " + redisPort);
    logger.info("redisTimeout                   : " + redisTimeout);
    logger.info("redisPassword                  : " + redisPassword);
    logger.info("redisDatabaseIndex             : " + redisDatabaseIndex);
    logger.info("redisPoolConfigMaxTotal        : " + redisPoolConfigMaxTotal);
    logger.info("redisPoolConfigMaxIdle         : " + redisPoolConfigMaxIdle);
    logger.info("redisPoolConfigMaxWaitMillis   : " + redisPoolConfigMaxWaitMillis);
    logger.info("redisPoolConfigTestOnBorrow    : " + redisPoolConfigTestOnBorrow);
    logger.info("redisPoolConfigTestOnReturn    : " + redisPoolConfigTestOnReturn);
    logger.info("redisPoolConfigTestWhileIdle   : " + redisPoolConfigTestWhileIdle);
    logger.info("**************Redis INFO******************");
  }

  //region Get And Set Method
  public Integer getPort() {
    return port;
  }

  public void setPort(Integer port) {
    this.port = port;
  }

  public String getChannelType() {
    return channelType;
  }

  public void setChannelType(String channelType) {
    this.channelType = channelType;
  }

  public String getProtocolType() {
    return protocolType;
  }

  public void setProtocolType(String protocolType) {
    this.protocolType = protocolType;
  }

  public String getMessageType() {
    return messageType;
  }

  public void setMessageType(String messageType) {
    this.messageType = messageType;
  }

  public ApplicationContext getApplicationContext() {
    return applicationContext;
  }

  public void setApplicationContext(ApplicationContext applicationContext) {
    this.applicationContext = applicationContext;
  }

  public String getCfgPackageName() {
    return cfgPackageName;
  }

  public void setCfgPackageName(String cfgPackageName) {
    this.cfgPackageName = cfgPackageName;
  }

  public String getCfgPrefix() {
    return cfgPrefix;
  }

  public void setCfgPrefix(String cfgPrefix) {
    this.cfgPrefix = cfgPrefix;
  }

  public String getCatalogDir() {
    return catalogDir;
  }

  public void setCatalogDir(String catalogDir) {
    this.catalogDir = catalogDir;
  }

  public String getCatalogFile() {
    return catalogFile;
  }

  public void setCatalogFile(String catalogFile) {
    this.catalogFile = catalogFile;
  }

  public String getCatalogMainNode() {
    return catalogMainNode;
  }

  public void setCatalogMainNode(String catalogMainNode) {
    this.catalogMainNode = catalogMainNode;
  }

  public String getCatalogAttribute() {
    return catalogAttribute;
  }

  public void setCatalogAttribute(String catalogAttribute) {
    this.catalogAttribute = catalogAttribute;
  }

  public String getXmlFileDir() {
    return xmlFileDir;
  }

  public void setXmlFileDir(String xmlFileDir) {
    this.xmlFileDir = xmlFileDir;
  }

  public String getRedisHost() {
    return redisHost;
  }

  public void setRedisHost(String redisHost) {
    this.redisHost = redisHost;
  }

  public Integer getRedisPort() {
    return redisPort;
  }

  public void setRedisPort(Integer redisPort) {
    this.redisPort = redisPort;
  }

  public Integer getRedisTimeout() {
    return redisTimeout;
  }

  public void setRedisTimeout(Integer redisTimeout) {
    this.redisTimeout = redisTimeout;
  }

  public String getRedisPassword() {
    return redisPassword;
  }

  public void setRedisPassword(String redisPassword) {
    this.redisPassword = redisPassword;
  }

  public Integer getRedisDatabaseIndex() {
    return redisDatabaseIndex;
  }

  public void setRedisDatabaseIndex(Integer redisDatabaseIndex) {
    this.redisDatabaseIndex = redisDatabaseIndex;
  }

  public Integer getRedisPoolConfigMaxTotal() {
    return redisPoolConfigMaxTotal;
  }

  public void setRedisPoolConfigMaxTotal(Integer redisPoolConfigMaxTotal) {
    this.redisPoolConfigMaxTotal = redisPoolConfigMaxTotal;
  }

  public Integer getRedisPoolConfigMaxIdle() {
    return redisPoolConfigMaxIdle;
  }

  public void setRedisPoolConfigMaxIdle(Integer redisPoolConfigMaxIdle) {
    this.redisPoolConfigMaxIdle = redisPoolConfigMaxIdle;
  }

  public Long getRedisPoolConfigMaxWaitMillis() {
    return redisPoolConfigMaxWaitMillis;
  }

  public void setRedisPoolConfigMaxWaitMillis(Long redisPoolConfigMaxWaitMillis) {
    this.redisPoolConfigMaxWaitMillis = redisPoolConfigMaxWaitMillis;
  }

  public Boolean getRedisPoolConfigTestOnBorrow() {
    return redisPoolConfigTestOnBorrow;
  }

  public void setRedisPoolConfigTestOnBorrow(Boolean redisPoolConfigTestOnBorrow) {
    this.redisPoolConfigTestOnBorrow = redisPoolConfigTestOnBorrow;
  }

  public Boolean getRedisPoolConfigTestOnReturn() {
    return redisPoolConfigTestOnReturn;
  }

  public void setRedisPoolConfigTestOnReturn(Boolean redisPoolConfigTestOnReturn) {
    this.redisPoolConfigTestOnReturn = redisPoolConfigTestOnReturn;
  }

  public Boolean getRedisPoolConfigTestWhileIdle() {
    return redisPoolConfigTestWhileIdle;
  }

  public void setRedisPoolConfigTestWhileIdle(Boolean redisPoolConfigTestWhileIdle) {
    this.redisPoolConfigTestWhileIdle = redisPoolConfigTestWhileIdle;
  }
  //endregion
}

redis-config-dev.properties redis的配置存放位置

# redis数据库配置
#   * @param poolConfig    连接池设置
#   * @param host          主机
#   * @param port          端口
#   * @param timeout       超时
#   * @param password      密码
#   * @param databaseIndex 数据库
#String host = "127.0.0.1";
#int port = 6379;
#int timeout = 2000;
#String password = "admin123";
#int databaseIndex = 16;
#   * @param poolConfig    连接池设置
#JedisPoolConfig poolConfig = new JedisPoolConfig();
#//设置最大连接数(100个足够用了,没必要设置太大)
#poolConfig.setMaxTotal(100);
#//最大空闲连接数
#poolConfig.setMaxIdle(10);
#//获取Jedis连接的最大等待时间(50秒)
#poolConfig.setMaxWaitMillis(50 * 1000);
#//在获取Jedis连接时,自动检验连接是否可用
#poolConfig.setTestOnBorrow(false);
#//在将连接放回池中前,自动检验连接是否有效
#poolConfig.setTestOnReturn(true);
#//自动测试池中的空闲连接是否都是可用连接
#poolConfig.setTestWhileIdle(true);
redis.host=127.0.0.1
redis.port=6379
redis.timeout=2000
redis.password=admin123
redis.databaseIndex=1
redis.poolConfig.maxTotal=100
redis.poolConfig.MaxIdle=10
redis.poolConfig.MaxWaitMillis=50000
redis.poolConfig.testOnBorrow=false
redis.poolConfig.testOnReturn=true
redis.poolConfig.testWhileIdle=true

xml-cfg-config-dev.properties xml-cfg的配置存放位置

# 静态数据的配置文件
#* String catalogDir = "/cfg/";
#* String catalogFile = "dataConfig.xml";
#* String catalogMainNode = "/config/file";
#* String catalogAttribute = "name";
#* String xmlFileDir = "/cfg/data-static-config/";
#* String cfgPackageName = "com.lizhaoblog.server.biz.entity.cfg.";
#* String cfgPrefix = "ConfigDataArrCfg";
#*
#* @param cfgPackageName   转换出来的类所在的包名
#* @param cfgPrefix        转换出来类的前缀
#* @param catalogDir       所有配置的清单文件 所在的文件夹
#* @param catalogFile      所有配置的清单文件
#* @param catalogMainNode  清单文件的标签
#* @param catalogAttribute 清单文件的标签名称
#* @param xmlFileDir       xml文件对应的路径

xml.cfg.cfgPackageName=com.lizhaoblog.server.biz.entity.cfg.
xml.cfg.cfgPrefix=ConfigDataArrCfg
xml.cfg.catalogDir=/cfg/
xml.cfg.catalogFile=dataConfig.xml
xml.cfg.catalogMainNode=/config/file
xml.cfg.catalogAttribute=name
xml.cfg.xmlFileDir=/cfg/data-static-config/

ApplicationContext.xml 将redis的配置和xml-cfg的配置加到spring中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
						http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
						http://www.springframework.org/schema/context
						http://www.springframework.org/schema/context/spring-context-4.2.xsd
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
						http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.2.xsd">

  <bean id="log4jInitializer" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"
              value="org.springframework.util.Log4jConfigurer"/>
    <property name="targetMethod" value="initLogging"/>
    <property name="arguments">
      <list>
        <value>classpath:log4j-dev.xml</value>
      </list>
    </property>
  </bean>

  <!-- 启用注解 -->
  <context:annotation-config/>

  <!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描 -->
  <context:component-scan base-package="com.lizhaoblog">
  </context:component-scan>

  <!--&lt;!&ndash;事务&ndash;&gt;-->
  <!--<tx:annotation-driven/>-->
  <!--定时任务-->
  <task:annotation-driven/>

  <!--指向的配置文件-->
  <bean id="cfgProps" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
      <list>
        <value>classpath:properties/server-config-dev.properties</value>
        <value>classpath:properties/db-config-dev.properties</value>
        <value>classpath:properties/xml-cfg-config-dev.properties</value>
        <value>classpath:properties/redis-config-dev.properties</value>
      </list>
    </property>
  </bean>
  <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="properties" ref="cfgProps">
    </property>
  </bean>



  <import resource="ApplicationContext-mysql.xml"/>

</beans>