Skip to content

Instantly share code, notes, and snippets.

@gyakkun
Created September 27, 2021 08:12
Show Gist options
  • Save gyakkun/00917b88e609411c53cc5453531c3912 to your computer and use it in GitHub Desktop.
Save gyakkun/00917b88e609411c53cc5453531c3912 to your computer and use it in GitHub Desktop.
Global get spring boot properties util class.
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
/**
* Read from application.properties by default priority.
**/
@Component
public class ThirdUtils implements EnvironmentAware {
public static Environment properties;
@Override
public void setEnvironment(Environment environment) {
properties = environment;
}
public static String getByKey(String key) {
if (properties == null) {
return "";
}
return properties.getProperty(key) == null ? "" : properties.getProperty(key);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment