Replies: 5 comments
-
Currently no, this is a known limitation. If we initialise type converters first we will have another issue report saying it is not possible to use I agree it is an unfortunately limitation, but I don't have a solution |
Beta Was this translation helpful? Give feedback.
-
yep true, but specifically the treatment of |
Beta Was this translation helpful? Give feedback.
-
I'm not sure how |
Beta Was this translation helpful? Give feedback.
-
ah yeah, so just thinking about using an If there is another way to execute logic early in init that would work too, like a |
Beta Was this translation helpful? Give feedback.
-
only thing I can think of which is a bit hacky is to use a |
Beta Was this translation helpful? Give feedback.
-
As per https://github.com/micronaut-projects/micronaut-core/blob/master/inject/src/main/java/io/micronaut/context/DefaultBeanContext.java#L2770
Event listeners are always constructed before
initializeTypeConverters
is called, which means that non-default TypeConverters likeTimeConverterRegistrar
are not available/registered, which leads to strange errors like:when using Duration values like
5s
in YAML config, i couldn't see this limitation documented anywhere, my mental model of it was that I write EventListeners like I write all the other beans/singletons and i'd expect injecting config with Duration to work like it would anywhere else.I can't find a good way to workaround it either, my first instinct was to create another EventListener to force the type converter registration, but
@Order
isn't honoured in EventListener construction, the ordering appears to be done after construction not before (which seems weird?)https://github.com/micronaut-projects/micronaut-core/blob/master/inject/src/main/java/io/micronaut/context/DefaultBeanContext.java#L1467
So i've had to do various hacks to make typeconverters be registered in tests vs actual runtime, quite fragile. Is there a better way to solve for this?
Beta Was this translation helpful? Give feedback.
All reactions