Class SystemPropertyUtils
java.lang.Object
org.springframework.boot.loader.util.SystemPropertyUtils
Helper class for resolving placeholders in texts. Usually applied to file paths.
A text may contain $ ...
placeholders, to be resolved as system properties:
e.g. $ user.dir
. Default values can be supplied using the ":" separator between
key and value.
Adapted from Spring.
- Since:
- 1.0.0
- Author:
- Juergen Hoeller, Rob Harrop, Dave Syer
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
getProperty
(String key) static String
getProperty
(String key, String defaultValue) static String
getProperty
(String key, String defaultValue, String text) Search the System properties and environment variables for a value with the provided key.static String
resolvePlaceholders
(String text) Resolve ${...} placeholders in the given text, replacing them with corresponding system property values.static String
resolvePlaceholders
(Properties properties, String text) Resolve ${...} placeholders in the given text, replacing them with corresponding system property values.
-
Field Details
-
PLACEHOLDER_PREFIX
Prefix for system property placeholders: "${".- See Also:
-
PLACEHOLDER_SUFFIX
Suffix for system property placeholders: "}".- See Also:
-
VALUE_SEPARATOR
Value separator for system property placeholders: ":".- See Also:
-
-
Constructor Details
-
SystemPropertyUtils
public SystemPropertyUtils()
-
-
Method Details
-
resolvePlaceholders
Resolve ${...} placeholders in the given text, replacing them with corresponding system property values.- Parameters:
text
- the String to resolve- Returns:
- the resolved String
- Throws:
IllegalArgumentException
- if there is an unresolvable placeholder- See Also:
-
resolvePlaceholders
Resolve ${...} placeholders in the given text, replacing them with corresponding system property values.- Parameters:
properties
- a properties instance to use in addition to Systemtext
- the String to resolve- Returns:
- the resolved String
- Throws:
IllegalArgumentException
- if there is an unresolvable placeholder- See Also:
-
getProperty
-
getProperty
-
getProperty
Search the System properties and environment variables for a value with the provided key. Environment variables inUPPER_CASE
style are allowed where System properties would normally belower.case
.- Parameters:
key
- the key to resolvedefaultValue
- the default valuetext
- optional extra context for an error message if the key resolution fails (e.g. if System properties are not accessible)- Returns:
- a static property value or null of not found
-