Created
September 27, 2021 08:12
-
-
Save gyakkun/00917b88e609411c53cc5453531c3912 to your computer and use it in GitHub Desktop.
Global get spring boot properties util class.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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