引起:java.lang.ClassNotFoundException:org.springframework.data.redis.connection.RedisStreamCommands

问题描述

当我在 save() 上执行 HBAlarmRepository 时,我收到以下错误和堆栈跟踪。

TaskUtils$LoggingErrorHandler | Unexpected error occurred in scheduled task.]#
java.lang.NoClassDefFoundError: org/springframework/data/redis/connection/RedisStreamCommands
        at org.redisson.spring.data.connection.RedissonConnectionFactory.getConnection(RedissonConnectionFactory.java:112)
        at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:132)
        at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:95)
        at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:82)
        at org.springframework.data.redis.core.Redistemplate.execute(Redistemplate.java:211)
        at org.springframework.data.redis.core.Redistemplate.execute(Redistemplate.java:184)
        at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:95)
        at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:236)
        at com.xyz.fm.dao.HBAlarmRepository.save(HBAlarmRepository.java:41)
        at com.xyz.fm.dao.HBAlarmRepository FastClassBySpringcglib$$2d7d1bf7.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.cglibAopProxy$cglibMethodInvocation.invokeJoinpoint(cglibAopProxy.java:749)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.cglibAopProxy$DynamicAdvisedInterceptor.intercept(cglibAopProxy.java:688)
        at com.xyz.fm.dao.HBAlarmRepository$$EnhancerBySpringcglib$$3451c6bc.save(<generated>)

这是我的相关文件

public class RedisConfigManager  {
    
    @Value("${spring.redis.address}")
    String hostName;
    
    @Value("${spring.redis.username}")
    String userName;
    @Value("${spring.redis.port}")
    int port;
    
    @Value("${spring.redis.password}")
    String password;

    Log log = LogFactory.getLog(RedisConfigManager.class);

    @Bean
    public RedissonConnectionFactory redissonConnectionFactory( RedissonClient redisson) {
        return new RedissonConnectionFactory(redisson);
    }
    
    @Bean
    public Redistemplate<String,HBAlarm> redistemplate(RedissonConnectionFactory connectionFactory) {
        Redistemplate<String,HBAlarm> template = new Redistemplate<>();
        template.setConnectionFactory(connectionFactory);
        return template;
    }
    
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        Config config = new Config();
              
        config.useMasterSlaveServers()
                .setMasteraddress("redis://"+hostName+":"+port)
                .setUsername(userName)
                .setPassword(password)
                .setDatabase(0);
        
        return Redisson.create(config);
        }
}


public class HBAlarm implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long alarmId;
    @Indexed
    String ip;
 //setter and getter   

}

@Component
@Repository
@Transactional
@Configuration
@EnableConfigurationProperties
public class HBAlarmRepository {

    @Autowired
    Redistemplate<String,HBAlarm> redistemplate;

    public void save(HBAlarm alarm) {
        redistemplate.opsForValue()
            .set(alarm.getIP(),alarm);
    }
    public void delete(HBAlarm alarm) {
        redistemplate.opsForValue().getoperations().delete(alarm.getIP());
    }

    public HBAlarm findByIp(String ip) {
        return redistemplate.opsForValue()
            .get(ip);
    }

}```

Can someone pls help what I am doing wrong . My pom has below 

        <dependency>
            <groupId>org.redisson</groupId>
            <artifactId>redisson-spring-boot-starter</artifactId>
            <version>3.15.0</version>
        </dependency>
        
        <dependency>
            <groupId>org.redisson</groupId>
            <artifactId>redisson</artifactId>
            <version>3.15.0</version>
        </dependency>


解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)