'Unable to retrieve value from Config Server using @Value annotation in Spring Boot

I have been trying to retrieve an attribute value from Config Server which has an application.properties file saves on GitHub repository. The property is defined in the application.properties file is not available in the microservices local application.properties file.

The access is defined by @Value{$"property"} annotation. However, the system is unable to read this property using @Value annotation. I have also added @Lazy annotation to an @Autowired variable to enable loading of properties file before the @Value annotation tries to read the property. It doesn't seem to work - I have tried everything that I have seen so far on StackOverflow as the recommended solution.

Interestingly, I am able to read this property through the following code;

@Autowired
Environment env

env.getProperty("property")

I am using Spring Boot version 2.2.0.RELEASE and Hoxton.SR11 spring-cloud.version

If anyone has a clue of why env.getProperty works and @Value annotation does not for a property read from Config Server using GitHub repository, please respond to this query.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source