Mezoo
Mezoo

Reputation: 769

Spring Boot custom HttpMessageConverter

How to configure spring boot to add a custom custom HttpMessageConverter ? I'm using

AbstractHttpMessageConverter

but I don't where adding in configuration. With Spring MVC Classic would be :

 <mvc:message-converters register-defaults="true">
      <bean class="com.mypackage.TsvMessageConverter"/>
   </mvc:message-converters>

But Spring boot, in Application.java ?

@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration
public class Application {}

Upvotes: 2

Views: 1884

Answers (1)

eparvan
eparvan

Reputation: 1729

If com.mypackage.TsvMessageConverter is extending from AbstractHttpMessageConverter class, then marking it with "@Component" annotation should be enough.

From spring docs:

You can contribute additional converters by simply adding beans of that type in a Spring Boot context. If a bean you add is of a type that would have been included by default anyway (like MappingJackson2HttpMessageConverter for JSON conversions) then it will replace the default value.

Upvotes: 5

Related Questions