Skip to content
Advertisement

@Value not getting the value from application.properties

im trying to get a value from the application.properties in a Spring boot app.

The class is defined with the tag @Component, I already tried @Service too, and with @PropertySource(“classpath:application.properties”) and without the @PropertySource but in any case they get the value.

JavaScript

The interface is defined like this

JavaScript

And the superior interface

JavaScript

In any case I tried without implementing the interface but it didn´t get it in any case

The application.properties is defined in this way:

JavaScript

Thanks in advance.

Advertisement

Answer

Usually @PropertySource annotation goes together with @Configuration annotation for your configuration class. It works for entire project. So, place it with your configuration and then in any class that is annotated as @Component, @Service @Controller etc you can use @Value annotation exactly the way you showed in your code. Here is a good article on the issue: Properties with Spring and Spring Boot

Advertisement