【发布时间】:2020-07-22 03:47:38
【问题描述】:
您好,我有一些自定义属性文件,例如 application.properties。我在这些文件中放置了一些属性。我的问题是 @ConditionalOnProperty 无法读取 customproperties 文件中的 myproperties。 如果我将相同的属性放在 application.properties ConditionalOnProperty 有效,但是当我将 myproperty 放在 customproperties 文件中时它不起作用。除了 ConditionalOnProperty 我从自定义属性文件中读取值没有任何问题。有没有办法从Spring Boot 中的 ConditionalOnProperty。
@Congiuration
@PropertySource("classpath:myproperties.properties")
@ConfigurationProperties(prefix="mycustomprop")
public class MyProperties{
private String myproperty;
@Configuration
@ConditionalOnProperty(name = "mycustomprop.myproperty", havingValue = "false") //not work when myproperty in customproperty file
public class MyConfiguration implements WebMvcConfigurer
@SpringBootApplication
@PropertySources({
@PropertySource("classpath:myproperties.properties")
})
public class MyApplication
【问题讨论】:
标签: spring spring-mvc properties-file