【问题标题】:Reading property from application.properties not working in java从 application.properties 读取属性在 java 中不起作用
【发布时间】:2020-11-17 17:02:54
【问题描述】:

我试图让这个 @Value 在 @Embeddable pojo 类中运行,但该值始终为 false。所有 application.properties 文件都正确填写。这可能是不可能的,因为它没有服务/控制器/配置?

@Embeddable
  public class WebDestination implements Serializable {
    
       @Value("${property.example}")
       private boolean example;


       public boolean isExample() {
            return example;
       }

       public void setExample(boolean example) {
           this.example= example;
       }
}

【问题讨论】:

标签: java spring-boot


【解决方案1】:

您只能在 Spring 容器管理的组件中使用 @Value("${property.example}") 注入属性值(使用 @Service@Controller@Component@Configuration 和...注释的类),您可以不要在其他任何地方使用它。

【讨论】:

    猜你喜欢
    • 2020-03-26
    • 2015-10-08
    • 2017-06-26
    • 2017-06-17
    • 1970-01-01
    • 2019-09-18
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多