背景:
有一老项目采用的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
不知道怎么解决了,希望有相关经验的大神能助我解惑。