gpt4 book ai didi

spring-boot - Spring Boot 自定义 HttpMessageConverter

转载 作者:行者123 更新时间:2023-12-04 02:50:21 24 4
gpt4 key购买 nike

如何配置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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com