这个 @Profile("!json") 是什么意思

what does this @Profile("!json") mean

我们正在使用这个,想知道它到底做了什么,在网上查看了详细的解释,但没有找到任何感叹的东西,配置文件,spring

Spring 中的“@Profile”功能实际上是 "Spring-boots" 中的一个功能。阅读 Spring boot docs 以获取有关如何配置和使用它的更多信息。

在您的示例中,它仅表示如果活动配置文件(使用 属性 spring.profiles.active 设置)为 [=18,则用 @Profile(“!json”) 注释的组件或组件不可用=].

Spring 引导中的示例

@Bean
@Profile("!prod")
public CommandLineRunner dataLoader(IngredientRepository repo,
UserRepository userRepo, PasswordEncoder encoder) {
...
}

此处,感叹号 (!) 否定配置文件名称。实际上,它指出 如果产品配置文件未激活,将创建 CommandLineRunner bean。