jooby-project / jooby

The modular web framework for Java and Kotlin
https://jooby.io
Apache License 2.0
1.68k stars 199 forks source link

Fix avaje module #3426

Closed kliushnichenko closed 1 month ago

kliushnichenko commented 2 months ago

@jknack AvajeInjectModule seems doesn't work as expected, at least for me. With a very basic example (reproduced in test https://github.com/jooby-project/jooby/commit/c9c81fdc85470df43b086abb257d611a6fd0574a) Jooby inner services injection fails with class cast exception, for example JsonMapper:

Caused by: java.lang.ClassCastException: class io.jooby.internal.ServiceRegistryImpl$$Lambda$458/0x0000000800dbf350 cannot be cast to class com.fasterxml.jackson.databind.json.JsonMapper (io.jooby.internal.ServiceRegistryImpl$$Lambda$458/0x0000000800dbf350 and com.fasterxml.jackson.databind.json.JsonMapper are in unnamed module of loader 'app')

I assume this is due to the fact that services already wrapped into lambda in singletone() https://github.com/jooby-project/jooby/blob/03bb5875786f9414c9339902cf015e264d06e173/jooby/src/main/java/io/jooby/internal/ServiceRegistryImpl.java#L61

Hence, the default binding need to be changed to beanScope.provideDefault(key.getType(), e.getValue()::get);

Also, Config binding was removed as it is already in service registry