0

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;
       }
}
Galadriel
  • 359
  • 5
  • 20
  • You can do it without Spring if you want: https://stackoverflow.com/questions/40835785/inject-application-properties-without-spring – Fullslack Jul 28 '20 at 09:34

1 Answers1

6

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.

Tashkhisi
  • 2,070
  • 1
  • 7
  • 20