springboot整合Redis java.lang.UnsupportedClassVersionError

养成好习惯第一天
新建一个maven项目想整合springboot跟redis,写了五行测试代码运行编译的时候直接报错

org/springframework/nativex/NativeListener has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

大概意思就是运行跟编译的版本不一致无法运行项目
随即百度找了一个多小时,网上大部分的原因是jdk跟jre版本不一致导致,修改项目依赖的jdk jre以及ideal的jdk版本一致即可,这是在网上看到最全面的一篇
https://www.cnblogs.com/hkgov/p/8074085.html
对照全文看了一遍发现我的环境配置没有问题,随即新建一个新项目测试发现全新的项目也无法运行
查看HELP.md发现以下内容

* The following dependencies are not known to work with Spring Native: 'Spring Boot DevTools, Spring Configuration
  Processor'. As a result, your application may not work as expected.
* The JVM level was changed from '1.8' to '11', review
  the [JDK Version Range](https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versions#jdk-version-range)
  on the wiki for more details.

以后新建的项目记得看一眼 HELP.md再删,白瞎一个多小时
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot中使用spring.redis.database属性时无效可能是因为以下原因: 1. 检查配置文件:首先,请确保你的配置文件(例如application.properties或application.yml)中正确地设置了spring.redis.database属性。确保在正确的位置设置了正确的数据库编号。如果在配置文件中设置了其他Redis属性,也请确保没有冲突或被覆盖。 2. Redis版本兼容性:如果你使用的是较旧的Redis版本,可能会导致该属性无效。确保你的Redis版本与Spring Boot版本兼容,并且支持使用该属性进行数据库选择。 3. Bean配置:在Spring Boot中,Redis连接是通过RedisConnectionFactory和RedisTemplate进行管理的。请确保你已正确配置这些Bean,并将其与spring.redis.database属性关联起来。例如,可以使用以下配置创建一个RedisTemplate Bean: ``` @Configuration public class RedisConfig { @Value("${spring.redis.database}") private int database; @Autowired private RedisConnectionFactory connectionFactory; @Bean public RedisTemplate<String, Object> redisTemplate() { RedisTemplate<String, Object> template = new RedisTemplate<>(); template.setConnectionFactory(connectionFactory); template.setKeySerializer(new StringRedisSerializer()); template.setValueSerializer(new GenericJackson2JsonRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer()); template.setEnableTransactionSupport(true); template.setEnableDefaultSerializer(true); template.afterPropertiesSet(); return template; } } ``` 请确保在配置类中注入了spring.redis.database属性,并将其应用于RedisTemplate。这将确保Redis连接将选择正确的数据库。 如果上述解决方案仍然无效,可能需要进行更详细的排查,例如检查Redis服务器状态,确认配置是否正确等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值