zqs164 2018-06-16 08:05 采纳率: 60%
浏览 11573
已结题

spring、redis整合,实例化ConnectionFactory出错

下面是我配置connectionFactory的代码

 @Bean
    public JedisConnectionFactory connectionFactory() throws IOException{
        Properties p = new Properties();
        // 加载redis配置文件
        p.load(CreateBeans.class.getResourceAsStream("/redis.properties"));
        // 配置JedisPool
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        poolConfig.setMaxIdle(Integer.parseInt(p.getProperty("redis.maxIdle")));
        poolConfig.setMaxTotal(Integer.parseInt(p.getProperty("redis.maxTotal")));
        poolConfig.setMaxWaitMillis(Integer.parseInt(p.getProperty("redis.maxWaitMillis")));
        poolConfig.setTestOnBorrow(Boolean.parseBoolean(p.getProperty("redis.testOnBorrow")));

        // 配置连接信息
        RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration();
        standaloneConfig.setHostName(p.getProperty("redis.host"));
        standaloneConfig.setPort(Integer.parseInt(p.getProperty("redis.port")));
        String pass = p.getProperty("redis.pass");
        if(pass != null && !pass.equals(""))
            standaloneConfig.setPassword(RedisPassword.of(pass));
        else
            standaloneConfig.setPassword(RedisPassword.none());

        DefaultJedisClientConfigurationBuilder builder = (DefaultJedisClientConfigurationBuilder) JedisClientConfiguration.builder();
        builder.usePooling();
        builder.poolConfig(poolConfig);
        builder.connectTimeout(Duration.ofMillis(Integer.parseInt(p.getProperty("redis.connTimeout"))));
        builder.readTimeout(Duration.ofMillis(Integer.parseInt(p.getProperty("redis.readTimeout"))));
        JedisClientConfiguration clientConfig = builder.build();

        return new JedisConnectionFactory(standaloneConfig, clientConfig);
    }

所引用的包
所引用的包
以上为引用的包,当然有些是配置redis不需要的。
下面是错误信息,

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.data.redis.connection.jedis.JedisConnectionFactory
    at com.dimbbs.beans.CreateBeans.connectionFactory(CreateBeans.java:43)
    at com.dimbbs.beans.CreateBeans$$EnhancerBySpringCGLIB$$6ae8678c.CGLIB$connectionFactory$0(<generated>)
    at com.dimbbs.beans.CreateBeans$$EnhancerBySpringCGLIB$$6ae8678c$$FastClassBySpringCGLIB$$d2c7309d.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
    at com.dimbbs.beans.CreateBeans$$EnhancerBySpringCGLIB$$6ae8678c.connectionFactory(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 48 more

是不是我缺少什么包?

  • 写回答

5条回答 默认 最新

  • 关注

    jedis客户端版本过高,

    将jedis的版本号换低版本就好了

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog