做的是自己的项目,但基本都该配置的都和老师一样配置了,百度了说是没注入Service,可是这早就注入了
来源:11-5 引入缓存技术之编码实现上
慕侠9209144
2019-10-22
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘assessServiceImpl’: Unsatisfied dependency expressed through field ‘jedisKeys’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jedisKeys’ defined in class path resource [spring/spring-redis.xml]: Cannot resolve reference to bean ‘jedisUtil’ while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jedisUtil’ defined in class path resource [spring/spring-redis.xml]: Cannot resolve reference to bean ‘jedisWritePool’ while setting bean property ‘jedisPool’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jedisPoolConfig’ defined in class path resource [spring/spring-redis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type ‘java.lang.String’ to required type ‘int’ for property ‘maxIdle’; nested exception is java.lang.NumberFormatException: For input string: "{redis.pool.maxIdle}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
@Service
public class AssessServiceImpl implements AssessService{
@Autowired
private AssessDao assessDao;
@Autowired
private JedisUtil.Keys jedisKeys;
@Autowired
private JedisUtil.Strings jedisStrings;
private static String ASSESSLISTKEY = "assesslist";
private static Logger logger = LoggerFactory.getLogger(AssessServiceImpl.class);
@Override
public void addAssess(Assess assess){
assessDao.insertAssess(assess);
}
@Override
@Transactional
public List<Assess> getAssessList(Assess assessCondition, int pageIndex, int pageSize) {
int rowIndex = PageCalculator.calculateRowIndex(pageIndex, pageSize);
String key = ASSESSLISTKEY;
List<Assess> assessList = null;
ObjectMapper mapper = new ObjectMapper();
if(!jedisKeys.exists(key)){
assessList = assessDao.queryAssess(assessCondition, rowIndex, pageSize);
String jsonString;
try {
jsonString = mapper.writeValueAsString(assessList);
} catch (JsonProcessingException e) {
e.printStackTrace();
logger.error(e.getMessage());
throw new AssessOperationException(e.getMessage());
}
jedisStrings.set(key, jsonString);
}else{
String jsonString = jedisStrings.get(key);
JavaType javaType = mapper.getTypeFactory().constructParametricType(ArrayList.class, Assess.class);
try {
assessList = mapper.readValue(jsonString, javaType);
} catch (JsonParseException e) {
e.printStackTrace();
logger.error(e.getMessage());
throw new AssessOperationException(e.getMessage());
} catch (JsonMappingException e) {
e.printStackTrace();
logger.error(e.getMessage());
throw new AssessOperationException(e.getMessage());
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage());
throw new AssessOperationException(e.getMessage());
}
}
return assessList;
}
}
public class JedisUtil {
//操作Key的方法
public Keys KEYS;
/** 对存储结构为String类型的操作 /
public Strings STRINGS;
/* Redis连接池对象 */
private JedisPool jedisPool;
/**
* 获取redis连接池
* @return
*/
public JedisPool getJedisPool() {
return jedisPool;
}
/**
* 设置redis连接池
* @param jedisPoolWriper
*/
public void setJedisPool(JedisPoolWriper jedisPoolWriper) {
this.jedisPool = jedisPoolWriper.getJedisPool();
}
/**
*从jedis连接池中获取jedis对象
* @return
*/
public Jedis getJedis(){
return jedisPool.getResource();
}
public class Keys{
/**
* 清除所以key
*/
public String flushAll(){
Jedis jedis = getJedis();
String stata = jedis.flushAll();
jedis.close();
return stata;
}
/**
* 产出keys对应的记录,可以试多个key
* @param String... keys
* @return 删除的记录数
*/
public long del(String... keys){
Jedis jedis = getJedis();
long count = jedis.del(keys);
jedis.close();
return count;
}
/**
* 判断key是否存在
* @param String key
* @return boolean
*/
public boolean exists(String key){
Jedis sjedis = getJedis();
boolean exis = sjedis.exists(key);
sjedis.close();
return exis;
}
/**
* 查找所有匹配给定的模式的键
* @param String
* key的表达式,*表示多个,?表示一个
* @return
*/
public Set<String> keys(String pattern){
Jedis jedis = getJedis();
Set<String> set = jedis.keys(pattern);
jedis.close();
return set;
}
}
public class Strings{
/**
* 根据key获取记录值
* @param key
* @return
*/
public String get(String key){
Jedis sjedis = getJedis();
String value = sjedis.get(key);
sjedis.close();
return value;
}
/**
* 添加记录,如果记录以及存在将覆盖原有的value
* @return
*/
public String set(String key,String value){
return set(SafeEncoder.encode(key),SafeEncoder.encode(value));
}
public String set(byte[] key,byte[] value){
Jedis jedis = getJedis();
String status = jedis.set(key, value);
jedis.close();
return status;
}
}
}
1回答
-
同学好,我看异常是 [spring/spring-redis.xml]: Failed to convert property value of type ‘java.lang.String’ to required type ‘int’ for property ‘maxIdle’; nested exception is java.lang.NumberFormatException: For input string: "{redis.pool.maxIdle}"
说的是{redis.pool.maxIdle}要求用int型而你配置是String,看看redis.properties里面是不是配置上相应的key了
012019-10-23
相似问题