Comments (11)
Can you try using the Jackson serializer https://micronaut-projects.github.io/micronaut-redis/latest/guide/#sessions
JDK serialisation will be deprecated soon
from micronaut-redis.
I tried without success. Shows the same error.
https://github.com/j1cs/drugstore-demo/blob/master/backend/src/main/resources/application.yml#L21
I'm using @Cacheable annotation in the services layer. It's a problem? Should I use it in the controller layer?
I followed this reference https://micronaut-projects.github.io/micronaut-redis/latest/guide/configurationreference.html#io.micronaut.configuration.lettuce.session.RedisHttpSessionConfiguration
from micronaut-redis.
I checked redis and still using java serializer:
127.0.0.1:6379> get "stores:ParametersKey: "
"\xac\xed\x00\x05sr\x00\x13java.util.ArrayListx\x81\xd2\x1d\x99\xc7a\x9d\x03\x00\x01I\x00\x04sizexp\x00\x00\a~w\x04\x00\x00\a~sr\x00\rme.jics.Store\x962\x93\x90\xbe\xe8\xf4\xd3\x02\x00\x0eL\x00\aaddresst\x00\x12Ljava/lang/String;L\x00\aborought\x00\x13Ljava/lang/Integer;L\x00\x0bboroughNameq\x00~\x00\x03L\x00\x0cclosingHourst\x00\x15Ljava/time/LocalTime;L\x00\x04datet\x00\x15Ljava/time/LocalDate;L\x00\x02idq\x00~\x00\x03L\x00\blatitudet\x00\x12Ljava/lang/Double;L\x00\blocationq\x00~\x00\x03L\x00\tlongitudeq\x00~\x00\aL\x00\x04nameq\x00~\x00\x03L\x00\nopeningDayq\x00~\x00\x03L\x00\x0copeningHoursq\x00~\x00\x05L\x00\x05phoneq\x00~\x00\x03L\x00\x06regionq\x00~\x00\x04xpt\x00\x15AVENIDA EL SALTO 2972sr\x00\x11java.lang.Integer\x12\xe2\xa0\xa4\xf7\x81\x878\x02\x00\x01I\x00\x05valuexr\x00\x10java.lang.Number\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00xp\x00\x00\x00zt\x00\bRECOLETAsr\x00\rjava.time.Ser\x95]\x84\xba\x1b\"H\xb2\x0c\x00\x00xpw\x03\x04\x13\xe1xsq\x00~\x00\x0ew\a\x03\x00\x00\a\xe5\x04\x1dxt\x00\x03534sr\x00\x10java.lang.Double\x80\xb3\xc2J)k\xfb\x04\x02\x00\x01D\x00\x05valuexq\x00~\x00\x0b\xc0@\xb3'>2j\xb6t\x00\bRECOLETAsq\x00~\x00\x12\xc0Q\xa8@\xb7\x14\xd4\xa4t\x00\nTORRES MPDt\x00\x06juevessq\x00~\x00\x0ew\x03\x04\n\xe1xt\x00\r+560225053570sq\x00~\x00\n\x00\x00\x00\asq\x00~\x00\x02t\x00\x0eSAN MARTIN 174sq\x00~\x00\n\x00\x00\x00St\x00\x04BUINsq\x00~\x00\x0ew\x02\x04\xe9xsq\x00~\x00\x0ew\a\x03\x00\x00\a\xe5\x04\x1dxt\x00\x03753sq\x00~\x00\x12\xc0@\xdd\xb2-\x0eV
Updated: setting @Cacheable in the controller didn't work too.
from micronaut-redis.
Now adding
redis:
uri: redis://${REDI_URI:localhost}
cache:
value-serializer: io.micronaut.jackson.serialize.JacksonObjectSerializer
It works when running with the openjdk:
127.0.0.1:6379> get "stores:ParametersKey: "
"[{\"date\":[2021,4,29],\"id\":\"534\",\"name\":\"Torres Mpd\",\"boroughName\":\"Recoleta\",\"location\":\"Recoleta\",\"address\":\"Avenida El Salto 2972\",\"openingHours\":[10,30],\"closingHours\":[19,30],\"phone\":\"+560225053570\",\"latitude\":-33.3996351,\"longitude\":-70.62894990000001,\"openingDay\":\"jueves\",\"region\":7,\"borough\":122},{\"date\":[2021,4,29],\"id\":\"753\",\"name\":\"Ahumada\",\"boroughName\":\"Buin\",\"location\":\"Buin\",\"address\":\"San Martin 174\",\"openingHours\":[8,30],\"closingHours\":[22,0],\"phone\":\"+560226313086\",\"latitude\":-33.732,\"longitude\":-70.735941,\"openingDay\":\"jueves\",\"region\":7,\"borough\":83},{\"date\":[2021,4,29],\"id\":\"754\",\"name\":\"Ahumada\",\"boroughName\":\"Buin\",\"location\":\"Buin\",\"address\":\"Bernardino Bravo 0115\",\"openingHours\":[9,0],\"closingHours\":[22,0],\"phone\":\"+560226313531\",\"latitude\":-33.733602,\"longitude\":-70.733803,\"openingDay\":\"jueves\",\"region\":7,\"borough\":83},{\"date\":[2021,4,29],\"id\":\"755\",\"name\":\"Buin\",\"boroughName\":\"Buin\",\"location\":\"Buin\",\"address\":\"Manuel Rodriguez 270\",\"openingHours\":[9,30],\"closingHours\":[20,30],\"phone\":\"+560228213917\",\"latitude\":-33.729515,\"longitude\":-70.739232,\"openingDay\":\"jueves\",\"r
However doesn't work with the native image:
15:48:21.841 [default-nioEventLoopGroup-1-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Failed to inject value for field [valueSerializer] of class: io.micronaut.configuration.lettuce.cache.DefaultRedisCacheConfiguration
Message: Error resolving field value [redis.cache.value-serializer]. Property doesn't exist or cannot be converted
Path Taken: new $StoreControllerDefinition$Intercepted([IStoreService service],BeanContext $beanContext,Qualifier $qualifier,List $interceptors) --> new $StoreServiceDefinition$Intercepted(PharmacyClient pharmacyClient,BeanContext $beanContext,Qualifier $qualifier,[List $interceptors]) --> new CacheInterceptor([CacheManager cacheManager],CacheErrorHandler errorHandler,AsyncCacheErrorHandler asyncCacheErrorHandler,ExecutorService ioExecutor,BeanContext beanContext) --> new DefaultCacheManager([List caches],Provider dynamicCacheManager) --> new RedisCache([DefaultRedisCacheConfiguration defaultRedisCacheConfiguration],RedisCacheConfiguration redisCacheConfiguration,ConversionService conversionService,BeanLocator beanLocator) --> DefaultRedisCacheConfiguration.valueSerializer
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [valueSerializer] of class: io.micronaut.configuration.lettuce.cache.DefaultRedisCacheConfiguration
from micronaut-redis.
Try add @TypeHint(io.micronaut.jackson.serialize.JacksonObjectSerializer.class)
to your Application
class
from micronaut-redis.
Didn't work:
16:30:35.727 [lettuce-nioEventLoop-5-4] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: I/O error occurred during deserialization: java.util.ArrayList; no valid constructor
io.micronaut.core.serialize.exceptions.SerializationException: I/O error occurred during deserialization: java.util.ArrayList; no valid constructor
Redis shows:
127.0.0.1:6379> get "stores:ParametersKey: "
"\xac\xed\x00\x05sr\x00\x13java.util.ArrayList\x18\xfc\xda\xcfW\xa5^h\x02\x00\x00xp"
(changes pushed btw)
from micronaut-redis.
Now adding
redis: uri: redis://${REDI_URI:localhost} cache: value-serializer: io.micronaut.jackson.serialize.JacksonObjectSerializer
It works when running with the openjdk:
127.0.0.1:6379> get "stores:ParametersKey: " "[{\"date\":[2021,4,29],\"id\":\"534\",\"name\":\"Torres Mpd\",\"boroughName\":\"Recoleta\",\"location\":\"Recoleta\",\"address\":\"Avenida El Salto 2972\",\"openingHours\":[10,30],\"closingHours\":[19,30],\"phone\":\"+560225053570\",\"latitude\":-33.3996351,\"longitude\":-70.62894990000001,\"openingDay\":\"jueves\",\"region\":7,\"borough\":122},{\"date\":[2021,4,29],\"id\":\"753\",\"name\":\"Ahumada\",\"boroughName\":\"Buin\",\"location\":\"Buin\",\"address\":\"San Martin 174\",\"openingHours\":[8,30],\"closingHours\":[22,0],\"phone\":\"+560226313086\",\"latitude\":-33.732,\"longitude\":-70.735941,\"openingDay\":\"jueves\",\"region\":7,\"borough\":83},{\"date\":[2021,4,29],\"id\":\"754\",\"name\":\"Ahumada\",\"boroughName\":\"Buin\",\"location\":\"Buin\",\"address\":\"Bernardino Bravo 0115\",\"openingHours\":[9,0],\"closingHours\":[22,0],\"phone\":\"+560226313531\",\"latitude\":-33.733602,\"longitude\":-70.733803,\"openingDay\":\"jueves\",\"region\":7,\"borough\":83},{\"date\":[2021,4,29],\"id\":\"755\",\"name\":\"Buin\",\"boroughName\":\"Buin\",\"location\":\"Buin\",\"address\":\"Manuel Rodriguez 270\",\"openingHours\":[9,30],\"closingHours\":[20,30],\"phone\":\"+560228213917\",\"latitude\":-33.729515,\"longitude\":-70.739232,\"openingDay\":\"jueves\",\"r
However doesn't work with the native image:
15:48:21.841 [default-nioEventLoopGroup-1-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Failed to inject value for field [valueSerializer] of class: io.micronaut.configuration.lettuce.cache.DefaultRedisCacheConfiguration Message: Error resolving field value [redis.cache.value-serializer]. Property doesn't exist or cannot be converted Path Taken: new $StoreControllerDefinition$Intercepted([IStoreService service],BeanContext $beanContext,Qualifier $qualifier,List $interceptors) --> new $StoreServiceDefinition$Intercepted(PharmacyClient pharmacyClient,BeanContext $beanContext,Qualifier $qualifier,[List $interceptors]) --> new CacheInterceptor([CacheManager cacheManager],CacheErrorHandler errorHandler,AsyncCacheErrorHandler asyncCacheErrorHandler,ExecutorService ioExecutor,BeanContext beanContext) --> new DefaultCacheManager([List caches],Provider dynamicCacheManager) --> new RedisCache([DefaultRedisCacheConfiguration defaultRedisCacheConfiguration],RedisCacheConfiguration redisCacheConfiguration,ConversionService conversionService,BeanLocator beanLocator) --> DefaultRedisCacheConfiguration.valueSerializer io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [valueSerializer] of class: io.micronaut.configuration.lettuce.cache.DefaultRedisCacheConfiguration
I think this is a bug. Because when you put the deserialization form in the application.yml
file and micronaut-redis is not able to inject the value correctly.
from micronaut-redis.
I was able to replicate the error in a newly created project: https://github.com/j1cs/micronaut-redis-cache-issue
I executed:
$ ./mvnw package -Dpackaging=native-image
[INFO] Executing: /usr/lib/jvm/java-11-graalvm/lib/svm/bin/native-image -cp ...
$ docker-compose up
Creating redis ... done
Attaching to redis
redis | 1:C 01 May 2021 17:09:27.724 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis | 1:C 01 May 2021 17:09:27.724 # Redis version=6.2.2, bits=64, commit=00000000, modified=0, pid=1, just started
$ ./target/cache
13:03:40.275 [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 34ms. Server Running: http://localhost:8080
$ curl http://localhost:8080/main
13:03:46.274 [default-nioEventLoopGroup-1-3] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Failed to inject value for field [valueSerializer] of class: io.micronaut.configuration.lettuce.cache.DefaultRedisCacheConfiguration
Message: Error resolving field value [redis.cache.value-serializer]. Property doesn't exist or cannot be converted
Path Taken: new MainController([MainService service]) --> new $MainServiceDefinition$Intercepted(BeanContext $beanContext,Qualifier $qualifier,[List $interceptors]) --> new CacheInterceptor([CacheManager cacheManager],CacheErrorHandler errorHandler,AsyncCacheErrorHandler asyncCacheErrorHandler,ExecutorService ioExecutor,BeanContext beanContext) --> new DefaultCacheManager([List caches],Provider dynamicCacheManager) --> new RedisCache([DefaultRedisCacheConfiguration defaultRedisCacheConfiguration],RedisCacheConfiguration redisCacheConfiguration,ConversionService conversionService,BeanLocator beanLocator) --> DefaultRedisCacheConfiguration.valueSerializer
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [valueSerializer] of class: io.micronaut.configuration.lettuce.cache.DefaultRedisCacheConfiguration
Message: Error resolving field value [redis.cache.value-serializer]. Property doesn't exist or cannot be converted
Path Taken: new MainController([MainService service]) --> new $MainServiceDefinition$Intercepted(BeanContext $beanContext,Qualifier $qualifier,[List $interceptors]) --> new CacheInterceptor([CacheManager cacheManager],CacheErrorHandler errorHandler,AsyncCacheErrorHandler asyncCacheErrorHandler,ExecutorService ioExecutor,BeanContext beanContext) --> new DefaultCacheManager([List caches],Provider dynamicCacheManager) --> new RedisCache([DefaultRedisCacheConfiguration defaultRedisCacheConfiguration],RedisCacheConfiguration redisCacheConfiguration,ConversionService conversionService,BeanLocator beanLocator) --> DefaultRedisCacheConfiguration.valueSerializer
Hope helps.
from micronaut-redis.
this error doesn't occur with version 3
from micronaut-redis.
I'm sorry. I was wrong the issue still persist.
from micronaut-redis.
Is there a workaround for this issue? Updated micronaut from 2.5.6 to 3.0.1. After that the native build threw this error:
"Failed to inject value for field [valueSerializer] of class: io.micronaut.configuration.lettuce.cache.DefaultRedisCacheConfiguration"
JacksonObjectSerializer
is part of the application.yml
and the @TypeHint
annotation:
redis:
uri: redis://${ELASTICACHE_HOST:localhost}:${ELASTICACHE_PORT:6379}
cache:
value-serializer: io.micronaut.jackson.serialize.JacksonObjectSerializer
@TypeHint(value = [JacksonObjectSerializer::class, java.util.ArrayList::class,
// Java standard data types must be mentioned explicitly to prevent graal ClassNotFoundExceptions of kotlin nullables
java.lang.Object::class,
java.lang.Long::class,
java.lang.Boolean::class,
java.lang.Integer::class,
java.lang.Float::class,
java.lang.Double::class,
java.lang.String::class,
])
With 2.5.6 the native build worked fine...
from micronaut-redis.
Related Issues (20)
- Configurable cache namespace HOT 2
- Update Micronaut-redis build
- Create BOM HOT 4
- Switch to using version catalog HOT 1
- Deprecate the embedded Redis server in favour of Testcontainers
- Dependency Dashboard
- password is not passed HOT 4
- [Redis] Micronaut does not support redis cluster configuration
- Non-Clustered Client Factory Does Not Work
- Redis hangs under GraalVM for 3.6.4-SNAPSHOT HOT 2
- Error setting `redis.verify-peer` to `false`
- Timeout erro when using only host and port in application.yml
- Support custom RedisCodec injection/configuration HOT 1
- Migrate to new configuration ascidoc macro
- Allow Redis to be disabled via configuration (prevent DefaultRedisConfiguration from loading) HOT 2
- Provide an option to retry a failed cache insert or read HOT 1
- Redis Support Connecting to ElastiCache with Master/Replica HOT 1
- Multiple threads to handle parallel Redis reactive commands
- Redis Lettuce Expiration Set Incorrectly HOT 2
- Del @Deprecated Redis
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from micronaut-redis.