Skip to content

Instantly share code, notes, and snippets.

@ahwinemman
Created June 1, 2020 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahwinemman/d53c611711d9863524a2da40d098f17a to your computer and use it in GitHub Desktop.
Save ahwinemman/d53c611711d9863524a2da40d098f17a to your computer and use it in GitHub Desktop.
This class is initiated at the start of the application and the values of the properties injected are logged in the terminal
package com.spring.injectprops;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.logging.Logger;
@Component
public class MainClass implements CommandLineRunner {
@Value("${base_url}")
private String baseUrl;
@Value("${username}")
private String username;
@Value("${password}")
private String password;
private static final Logger LOGGER = Logger.getLogger(MainClass.class.getName());
@Override
public void run(String... args) throws Exception {
LOGGER.info("The value of the baseUrl is : " + baseUrl);
LOGGER.info("The value of the username is : " + username);
LOGGER.info("The value of the password is : " + password);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment