follow these steps. 1:- create your configuration class like below you can see
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.beans.factory.annotation.Value;
@Configuration
public class YourConfiguration{
// passing the key which you set in application.properties
@Value("${some.pro}")
private String somePro;
// getting the value from that key which you set in application.properties
@Bean
public String getsomePro() {
return somePro;
}
}
2:- when you have a configuration class then inject in the variable from a configuration where you need.
@Component
public class YourService {
@Autowired
private String getsomePro;
// now you have a value in getsomePro variable automatically.
}