小侠csdnn 2018-09-12 07:18 采纳率: 50%
浏览 2570
已采纳

hibernate整合redis二级缓存问题

背景:
有一老项目采用的hibernate配合ehcache作为二级缓存,现因需求需要更换redis来做hibernate的二级缓存。大家不用问为什么不换掉hibernate,因为是老项目所以风险太大。
问题:
1、我按照网上做法导入了若干个jar包,见图:
图片说明
2、spring中sessionFactory也配置了二级缓存:

hibernate.cache.use_query_cache = true
hibernate.cache.use_second_level_cache = true
hibernate.cache.use_structured_entries = true
hibernate.cache.region_prefix = hibernate
hibernate.cache.region.factory_class = org.hibernate.cache.redis.hibernate5.RedisRegionFactory
hibernate.cache.provider_configuration_file_resource_path = hibernate-redis.properties

3、也分别创建了hibernate-redis.properties和redisson.yaml,内容分别如下
(1)hibernate-redis.properties:

 redisson-config = classpath:redisson.yaml 
redis.expiryInSeconds.default = 360
redis.expiryInSeconds.hibernate.common = 0
redis.expiryInSeconds.hibernate.account = 1200

(2)redisson.yaml

 singleServerConfig:
  idleConnectionTimeout: 10000
  pingTimeout: 5000
  connectTimeout: 5000
  timeout: 5000
  retryAttempts: 1
  retryInterval: 1000
  reconnectionTimeout: 3000
  failedAttempts: 1
  password: 123456
  subscriptionsPerConnection: 3
  clientName: null
  address: [
   "redis://127.0.0.1:6379"
   ]
  subscriptionConnectionMinimumIdleSize: 1
  subscriptionConnectionPoolSize: 3
  connectionMinimumIdleSize: 3
  connectionPoolSize: 3
  database: 0
  dnsMonitoring: false
  dnsMonitoringInterval: 5000
threads: 0
codec: !<org.redisson.codec.SnappyCodec> {}
useLinuxNativeEpoll: false
eventLoopGroup: null

4、redis也正常运行
5、最后运行程序报了一个错:

 Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.net.URI` out of START_ARRAY token
 at [Source: (URL); line: 14, column: 4] (through reference chain: org.redisson.config.Config["singleServerConfig"]->org.redisson.config.SingleServerConfig["address"])
    at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
    at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1342)
    at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1138)
    at com.fasterxml.jackson.databind.deser.std.StdDeserializer._deserializeFromArray(StdDeserializer.java:674)
    at com.fasterxml.jackson.databind.deser.std.FromStringDeserializer.deserialize(FromStringDeserializer.java:164)
    at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:136)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
    at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:127)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:288)
    at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
    at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2959)
    at org.redisson.config.ConfigSupport.fromYAML(ConfigSupport.java:169)
    at org.redisson.config.Config.fromYAML(Config.java:754)
    at org.hibernate.cache.redis.client.RedisClientFactory.createRedisClient(RedisClientFactory.java:63)
    ... 57 more
不知道怎么解决了,希望有相关经验的大神能助我解惑。
  • 写回答

5条回答 默认 最新

  • 小侠csdnn 2018-09-13 04:10
    关注

    删掉了,虽然不报错了,但一运行程序(包括Hibernate查询数据库的程序),就会报错,如下:

     Caused by: java.lang.AbstractMethodError: org.hibernate.cache.redis.hibernate5.regions.RedisQueryResultsRegion.get(Lorg/hibernate/engine/spi/SharedSessionContractImplementor;Ljava/lang/Object;)Ljava/lang/Object;
        at org.hibernate.cache.internal.StandardQueryCache.getCachedResults(StandardQueryCache.java:245) ~[hibernate-5.3.5.jar:?]
        at org.hibernate.cache.internal.StandardQueryCache.get(StandardQueryCache.java:161) ~[hibernate-5.3.5.jar:?]
        at org.hibernate.loader.Loader.getResultFromQueryCache(Loader.java:2619) ~[hibernate-5.3.5.jar:?]
        at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2527) ~[hibernate-5.3.5.jar:?]
        at org.hibernate.loader.Loader.list(Loader.java:2499) ~[hibernate-5.3.5.jar:?]
        at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109) ~[hibernate-5.3.5.jar:?]
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1936) ~[hibernate-5.3.5.jar:?]
        at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:370) ~[hibernate-5.3.5.jar:?]
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-5.0.8.jar:?]
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-5.0.8.jar:?]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-5.0.8.jar:?]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) ~[spring-5.0.8.jar:?]
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) ~[spring-5.0.8.jar:?]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-5.0.8.jar:?]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-5.0.8.jar:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
        at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:871) ~[ognl-3.0.19.jar:?]
        at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1294) ~[ognl-3.0.19.jar:?]
        ... 92 more
    

    这个错儿我也查了一下,没找到相似的。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 Yolov5训练报错
  • ¥15 Unity发布gzip压缩的webgl之后让浏览器可以正常显示画面
  • ¥15 有没有人知道这种提示怎么关?现在不做ts项目了不知道咋关了,求解,现在我以前的js项目都是这种提示了
  • ¥15 为什么mysql做了碎片化处理data_free还是很高
  • ¥15 single positional indexer is out-of-bounds
  • ¥15 LSTM 模型数据量需要多少?
  • ¥15 mysql数据抓包开发报表
  • ¥15 linux系统下安装office打不开
  • ¥20 rsync脚本分发错误,文件不齐全
  • ¥15 labview顺序结构与时间延时