public abstract class BusinessIdGenerateAbstract implements Serializable{
protected JedisPool jedisPool;
protected void fromRedis(String idName,Queue queue){
try {
jedis = jedisPool.getResource();
Map<String,String> model = jedis.hgetAll(idName);
Long redisCurrentId = Long.valueOf(model.get("currentId"));
for (int i = 1; i <= increase; i++) {
redisCurrentId += 1;
queue.offer(redisCurrentId);
}
model.put("currentId", String.valueOf(redisCurrentId));
jedis.hmset(idName,model);
} catch (Exception e) {
e.printStackTrace();
logger.error("fromRedis--failed");
}finally{
if(null != jedis) {
jedisPool.returnResource(jedis);
}
}
}
//spring配置
<bean id="businessIdGenerateAbstract" class="com.fangcang.sequence.entity.BusinessIdGenerateAbstract" abstract="true">
<property name="jedisPool" ref="jedisPool"></property>
</bean>
<bean id="jedisPool" class="redis.clients.jedis.JedisPool">
<constructor-arg index="0" ref="jedisPoolConfig" />
<constructor-arg index="1" value="${redis.ip}" />
<constructor-arg index="2" value="${redis.port}" type="int"/>
<constructor-arg index="3" value="${common.redis.timeout}" type="int"/>
<constructor-arg index="4" value="${common.redis.password}" />
</bean>
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxIdle" value="${common.redis.maxIdle}"></property>
<property name="minIdle" value="${common.redis.minIdle}"></property>
<property name="maxTotal" value="${common.redis.maxTotal}"></property>
<property name="maxWaitMillis" value="${common.redis.maxWait}"></property>
</bean>
启动Jboss后,调用方法时,报错,jedisPool is null