标签:bundle bsp import url lin 内容 cep line tostring
redis.maxIdle=30 redis.minIdle=10 redis.maxTotal=100 redis.url=192.168.204.128 redis.port=6379
package ${enclosing_package}; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; public class ${primary_type_name} { private static JedisPool pool = null; static{ //加载配置文件 InputStream in = ${primary_type_name}.class.getClassLoader().getResourceAsStream("redis.properties"); Properties pro = new Properties(); try { pro.load(in); } catch (IOException e) { e.printStackTrace(); } //获得池子对象 JedisPoolConfig poolConfig = new JedisPoolConfig(); poolConfig.setMaxIdle(Integer.parseInt(pro.get("redis.maxIdle").toString()));//最大闲置个数 poolConfig.setMinIdle(Integer.parseInt(pro.get("redis.minIdle").toString()));//最小闲置个数 poolConfig.setMaxTotal(Integer.parseInt(pro.get("redis.maxTotal").toString()));//最大连接数 pool = new JedisPool(poolConfig,pro.getProperty("redis.url") , Integer.parseInt(pro.get("redis.port").toString())); } //获得jedis资源的方法 public static Jedis getJedis(){ return pool.getResource(); } }
package ${enclosing_package}; import java.util.ResourceBundle; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.JedisPoolConfig; public class ${primary_type_name} { private static JedisPool pool = null; private static int maxIdle; private static int minIdle; private static int maxTotal; private static String host; private static int port; static { // 1 加载配置文件 ResourceBundle bundle = ResourceBundle.getBundle("redis"); // 2 获得连接池配置对象 JedisPoolConfig poolConfig = new JedisPoolConfig(); // 3 获取配置文件的内容 maxIdle = Integer.parseInt(bundle.getString("redis.maxIdle")); //最大闲置个数 minIdle = Integer.parseInt(bundle.getString("redis.minIdle")); //最小闲置个数 maxTotal = Integer.parseInt(bundle.getString("redis.minIdle")); //最大连接数 host =bundle.getString("redis.url"); //host地址 port = Integer.parseInt(bundle.getString("redis.port")); //端口 // 4 设置配置项目 poolConfig.setMaxIdle(maxIdle); poolConfig.setMinIdle(minIdle); poolConfig.setMaxTotal(maxTotal); // 5 获得池子对象 pool = new JedisPool(poolConfig, host, port); } //获得jedis资源的方法 public static Jedis getJedis() { return pool.getResource(); } }
标签:bundle bsp import url lin 内容 cep line tostring
原文地址:https://www.cnblogs.com/lywJ/p/10710849.html