fix redis反序列化异常问题

master
疯狂的狮子li 5 years ago
parent ca903ebd1f
commit 3131b7ea9d

@ -12,7 +12,7 @@ import java.util.Set;
/**
*
*
*
* @author ruoyi
*/
@ -81,6 +81,7 @@ public class LoginUser implements UserDetails
return user.getPassword();
}
@JsonIgnore
@Override
public String getUsername()
{
@ -99,7 +100,7 @@ public class LoginUser implements UserDetails
/**
* ,
*
*
* @return
*/
@JsonIgnore
@ -111,7 +112,7 @@ public class LoginUser implements UserDetails
/**
* (),
*
*
* @return
*/
@JsonIgnore
@ -123,7 +124,7 @@ public class LoginUser implements UserDetails
/**
* ,
*
*
* @return
*/
@JsonIgnore
@ -133,6 +134,7 @@ public class LoginUser implements UserDetails
return true;
}
@JsonIgnore
@Override
public Collection<? extends GrantedAuthority> getAuthorities()
{

@ -1,18 +1,13 @@
package com.ruoyi.framework.config;
import com.alibaba.fastjson.support.spring.GenericFastJsonRedisSerializer;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.jsontype.impl.LaissezFaireSubTypeValidator;
/**
* redis
@ -30,19 +25,15 @@ public class RedisConfig extends CachingConfigurerSupport
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory);
Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Object.class);
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
serializer.setObjectMapper(mapper);
GenericFastJsonRedisSerializer serializer = new GenericFastJsonRedisSerializer();
StringRedisSerializer keySerializer = new StringRedisSerializer();
// 使用StringRedisSerializer来序列化和反序列化redis的key值
template.setKeySerializer(new StringRedisSerializer());
template.setKeySerializer(keySerializer);
template.setValueSerializer(serializer);
// Hash的key也采用StringRedisSerializer的序列化方式
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(keySerializer);
template.setHashValueSerializer(serializer);
template.afterPropertiesSet();

@ -1,12 +1,5 @@
package com.ruoyi.framework.web.service;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
@ -22,6 +15,14 @@ import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.framework.manager.AsyncManager;
import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
*
@ -102,6 +103,7 @@ public class SysLoginService
{
user.setLoginIp(IpUtils.getIpAddr(ServletUtils.getRequest()));
user.setLoginDate(DateUtils.getNowDate());
user.setUpdateBy(user.getUserName());
userService.updateUserProfile(user);
}
}

Loading…
Cancel
Save