Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatterAutoConfiguration要输出objectMapperFormatter是有隐含条件的 #102

Open
leogan12 opened this issue May 7, 2024 · 1 comment

Comments

@leogan12
Copy link

leogan12 commented May 7, 2024

358-370页 9.4.2 bean的条件注解 一章用到的例子FormatterAutoConfiguration要输出objectMapperFormatter的前提条件是 JacksonAutoConfiguration.JacksonObjectMapperConfiguration#jacksonObjectMapper matched ,这里的隐含条件是JacksonAutoConfiguration要先于FormatterAutoConfiguration配置好,您的例子刚好,正确输出了[Bean name : objectMapperFormatter] JsonFormatter.format(data) : {"name":"小马哥"},而我的例子始终只能输出jsonFormatter,不知何故?

后来我在您的例子上加上
@AutoConfigureBefore(JacksonAutoConfiguration.class)
public class FormatterAutoConfiguration
后,也只能输出jsonFormatter

而在我的例子上加上
@AutoConfigureAfter(JacksonAutoConfiguration.class)
public class FormatterAutoConfiguration
后,也能正确输出objectMapperFormatter

建议您再版时,加上这个隐含条件

@kuluome
Copy link

kuluome commented May 28, 2024

这里我今天看到这里也发现了,windows11,debug之后发现加载FormatterAutoConfiguration中的三个bean的时候,去根据条件判断是否注册的时候ObjectMapper的Bean是还没有注册的,发生和你一样的情况,小马哥后续确实可以标注一下,不过我搜了一下小马哥在这个 #53 回复了这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants