0

I have to get a enviromental variable and I can't inject.

@Component
@EnableConfigurationProperties
public class Client {

    @Autowired
    RestTemplate restTemplate;

    @Value("${BASE_URL}")
    private String baseUrl;

    public List<Car> getAllCars(){
        ResponseEntity<List<Car>> res = restTemplate.exchange(baseUrl.concat("/car"),HttpMethod.GET,null, 
                new ParameterizedTypeReference<List<Car>>() {});
        return res.getBody();
    }
}

I am not capable of inject basUrl that I have in the env.

Could some tell how I can do it?

I read the following pages and I am very beginner because I can't understan anything. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html https://www.mkyong.com/spring-boot/spring-boot-configurationproperties-example/

Also I have tried with

@Autowired
private Environment env;

Always the result is null.

Michael
  • 41,989
  • 11
  • 82
  • 128

1 Answers1

0

please try

@Value("#{systemProperties['BASE_URL']}")