如何配置spring boot添加自定义custom HttpMessageConverter ? 我正在使用
AbstractHttpMessageConverter
但我不知道在哪里添加配置。 使用 Spring MVC Classic 将是:
<mvc:message-converters register-defaults="true">
<bean class="com.mypackage.TsvMessageConverter"/>
</mvc:message-converters>
但是Spring boot,在Application.java中?
@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration
public class Application {}
最佳答案
如果 com.mypackage.TsvMessageConverter
是从 AbstractHttpMessageConverter
类扩展的,那么用“@Component”注释标记它就足够了。
来自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.
关于spring-boot - Spring Boot 自定义 HttpMessageConverter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40328535/