Spring Webflux Codec: Can a custom codec be added the the list of default codecs globally?

I’ve been shown how to add custom Codecs to webflux:inbound-gateway and webflux:outbound-gateway declarations using respectively the codec-configurer and web-client attributes. How to add HttpMessageWriter<> to webflux outbound-gateway

Is there a way (and perhaps even a simple way) of adding one’s custom codec to the list of default codecs and hence avoid having to declare these in the endpoints?

>Solution :

See CodecConfigurerFactory. You can use a CodecConfigurer.properties file to specify your custom strategies for those codecs:

# Default CodecConfigurer implementation classes for static Client/ServerCodecConfigurer.create() calls.
# Not meant to be customized by application developers; simply instantiate custom impl classes instead.

org.springframework.http.codec.ClientCodecConfigurer=org.springframework.http.codec.support.DefaultClientCodecConfigurer
org.springframework.http.codec.ServerCodecConfigurer=org.springframework.http.codec.support.DefaultServerCodecConfigurer

Leave a Reply