Galadriel
Galadriel

Reputation: 369

Reading property from application.properties not working in java

I am trying to get this @Value running in an @Embeddable pojo class, but the value ist always false. All application.properties files are filled correctly. Is it maybe just not possible, because it's no srvice/ controller/ configuration?

@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;
       }
}

Upvotes: 0

Views: 324

Answers (1)

Tashkhisi
Tashkhisi

Reputation: 2262

You can only inject property value using @Value("${property.example}") in components that are managed by Spring container (classes that are annotated with @Service, @Controller, @Component, @Configuration and ...), you can't use it anywhere else.

Upvotes: 6

Related Questions