代码:一段几个月前的老代码 变更: 将fastjson从1.2.57升级到1.2.61
异常堆栈:java.lang.NoSuchMethodError: com.alibaba.fastjson.serializer.JavaBeanSerializer.processValue(Lcom/alibaba/fastjson/serializer/JSONSerializer;Lcom/alibaba/fastjson/serializer/BeanContext;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;Ljava/lang/Integer;
at com.alibaba.fastjson.serializer.ASMSerializer_1_CurrentUserBO.writeNormal(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.ASMSerializer_1_CurrentUserBO.write(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:285) ~[fastjson-1.2.61.jar:na]
at com.alibaba.fastjson.JSON.toJSONBytes(JSON.java:825) ~[fastjson-1.2.61.jar:na]
at com.alibaba.fastjson.JSON.toJSONBytes(JSON.java:796) ~[fastjson-1.2.61.jar:na]
at com.alibaba.fastjson.JSON.toJSONBytes(JSON.java:789) ~[fastjson-1.2.61.jar:na]
at com.alibaba.fastjson.JSON.toJSONBytes(JSON.java:771) ~[fastjson-1.2.61.jar:na]
at com.alibaba.fastjson.JSON.toJSONBytes(JSON.java:698) ~[fastjson-1.2.61.jar:na]
at com.alibaba.fastjson.JSON.toJSONBytes(JSON.java:687) ~[fastjson-1.2.61.jar:na]
at com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer.serialize(GenericFastJsonRedisSerializer.java:24) ~[fastjson-1.2.61.jar:na]
at org.springframework.data.redis.core.AbstractOperations.rawValue(AbstractOperations.java:117) ~[spring-data-redis-1.8.12.RELEASE.jar:na]
at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:180) ~[spring-data-redis-1.8.12.RELEASE.jar:na]
at com.user.app.cache.impl.UserCacheServiceImpl.cacheCurrentLoginUser(UserCacheServiceImpl.java:48) ~[classes/:na]
at com.user.app.service.impl.LoginServiceImpl.tokenLogin(LoginServiceImpl.java:112) ~[classes/:na]
at com.user.app.service.impl.LoginServiceImpl.mobileLogin(LoginServiceImpl.java:86) ~[classes/:na]
at com.user.app.service.impl.MobileLoginServiceImpl.login(MobileLoginServiceImpl.java:51) ~[classes/:na]
at com.user.app.controller.AppUserController.login(AppUserController.java:130) ~[classes/:na]
at com.user.app.controller.AppUserController$$FastClassBySpringCGLIB$$7dc4b154.invoke(<generated>) ~[classes/:na]
相关的java代码:
@Override
public void cacheCurrentLoginUser(Integer userId, Integer sourceType, String mobile, Integer invoiceInfoId) {
CurrentUserBO currentUserBO = new CurrentUserBO();
currentUserBO.setMobile(mobile);
currentUserBO.setInvoiceId(invoiceInfoId);
String key = CacheKeyManager.fillKey(CURRENT_USER_KEY, userId, sourceType);
redisTemplate.opsForValue().set(key, currentUserBO, COOKIE_MAX_AGE, TimeUnit.SECONDS); //此行代码报错
}
RedisTemplate中FastJsonRedisSerializer的使用:
@Bean
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
GenericFastJsonRedisSerializer fastJsonRedisSerializer = new GenericFastJsonRedisSerializer();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setDefaultSerializer(fastJsonRedisSerializer);//设置默认的Serialize,包含 keySerializer & valueSerializer
redisTemplate.setConnectionFactory(redisConnectionFactory);
return redisTemplate;
}
涉及到的BO:
import lombok.Data;
/**
* @Description:
*/
@Data
public class CurrentUserBO {
/**
* 抬头Id
*/
private Integer invoiceId;
/**
* userId和invoiceId关联的手机号
*/
private String mobile;
}