下面是我配置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
是不是我缺少什么包?