账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    Redis Template<String, User> Exception
    22
    0

    My code like this:

    Java:

    @Autowired
    private RedisTemplate<String,User> myTemplate;
    
    @Override
    public String login(String email, String password) {
        User user = this.userRepository.findByEmailAndPassword(email, password);
    
        System.out.println(user);
    
        if (user == null)  return null;
    
        String key1 = "lic" + "$" + user.getId() + "$" + user.getRole() + "$" + user.getName() + "$" + user.getEmail();
    
        ValueOperations<String, User> ops = this.myTemplate.opsForValue();
    
        if (!this.myTemplate.hasKey(key1)) {
            ops.set(key1, user);
        }
        return key1;
    }
    when app run, inject bean ,like this:
    
    @SpringBootApplication
    public class ApplicationApp extends WebMvcConfigurerAdapter {
    
    
    //    @Autowired
    //    private RedisTemplate<String,String> template;
    
    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
        return new JedisConnectionFactory();
    }
    
    @Bean
    RedisTemplate<String, User> redisTemplate() {
        final RedisTemplate<String, User> template = new RedisTemplate<String, User>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setHashValueSerializer(new GenericToStringSerializer<User>(User.class));
        template.setValueSerializer(new GenericToStringSerializer<User>(User.class));
        return template;
    }
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // super.addInterceptors(registry);
        registry.addInterceptor(new AuthorAccess()).addPathPatterns("/api/sc/**");
    }
    
    public static void main(String[] args) throws Exception {
        SpringApplication.run(ApplicationApp.class, args);
    }
    }

    then , call login service found error like this:

    org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type com.qycloud.oatos.license.domain.User to type java.lang.String

    Trying to implement as I got resources from internet, but not solved.

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 飞天白鹭 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部