Package org.springframework.core

# Class SpringProperties

java.lang.Object
org.springframework.core.SpringProperties

public final class SpringProperties extends Object
Static holder for local Spring properties, i.e. defined at the Spring library level.

Reads a `spring.properties` file from the root of the classpath and also allows for programmatically setting properties via `setProperty(java.lang.String, java.lang.String)`. When retrieving properties, local entries are checked first, with JVM-level system properties checked next as a fallback via `System.getProperty(java.lang.String)`.

This is an alternative way to set Spring-related system properties such as `spring.getenv.ignore` and `spring.beaninfo.ignore`, in particular for scenarios where JVM system properties are locked on the target platform (for example, WebSphere). See `setFlag(java.lang.String)` for a convenient way to locally set such flags to `"true"`.

Since:
  3.2.7
Author:
  Juergen Hoeller
See Also:
  - `AotDetector.AOT_ENABLED`
  - `org.springframework.beans.StandardBeanInfoFactory#IGNORE_BEANINFO_PROPERTY_NAME`
  - `org.springframework.beans.factory.support.DefaultListableBeanFactory#STRICT_LOCKING_PROPERTY_NAME`
  - `AbstractEnvironment.IGNORE_GETENV_PROPERTY_NAME`
  - `org.springframework.expression.spel.SpelParserConfiguration#SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME`
  - `org.springframework.expression.spel.SpelParserConfiguration#SPRING_EXPRESSION_MAX_OPERATIONS_PROPERTY_NAME`
  - `org.springframework.jdbc.core.StatementCreatorUtils#IGNORE_GETPARAMETERTYPE_PROPERTY_NAME`
  - `org.springframework.jndi.JndiLocatorDelegate#IGNORE_JNDI_PROPERTY_NAME`
  - `SpringObjenesis.IGNORE_OBJENESIS_PROPERTY_NAME`
  - `org.springframework.test.context.NestedTestConfiguration#ENCLOSING_CONFIGURATION_PROPERTY_NAME`
  - `org.springframework.test.context.TestConstructor#TEST_CONSTRUCTOR_AUTOWIRE_MODE_PROPERTY_NAME`
  - `org.springframework.test.context.cache.ContextCache#MAX_CONTEXT_CACHE_SIZE_PROPERTY_NAME`

## Method Summary

Modifier and Type
Method
Description
`static Boolean`
`checkFlag(String key)`
Retrieve the flag for the given property key, returning `null` instead of `false` in case of no actual flag set.
`static boolean`
`getFlag(String key)`
Retrieve the flag for the given property key.
`static String`
`getProperty(String key)`
Retrieve the property value for the given key, checking local Spring properties first and falling back to JVM-level system properties.
`static void`
`setFlag(String key)`
Programmatically set a local flag to "true", overriding an entry in the `spring.properties` file (if any).
`static void`
`setFlag(String key, boolean value)`
Programmatically set a local flag to the given value, overriding an entry in the `spring.properties` file (if any).
`static void`
`setProperty(String key, String value)`
Programmatically set a local property, overriding an entry in the `spring.properties` file (if any).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### setProperty

public static void setProperty(String key, @Nullable String value)
Programmatically set a local property, overriding an entry in the `spring.properties` file (if any).

Parameters:
  `key` - the property key
  `value` - the associated property value, or `null` to reset it

### getProperty

@Nullable public static String getProperty(String key)
Retrieve the property value for the given key, checking local Spring properties first and falling back to JVM-level system properties.

Parameters:
  `key` - the property key
Returns:
  the associated property value, or `null` if none found

### setFlag

public static void setFlag(String key)
Programmatically set a local flag to "true", overriding an entry in the `spring.properties` file (if any).

Parameters:
  `key` - the property key

### setFlag

public static void setFlag(String key, boolean value)
Programmatically set a local flag to the given value, overriding an entry in the `spring.properties` file (if any).

Parameters:
  `key` - the property key
  `value` - the associated boolean value
Since:
  6.2.6

### getFlag

public static boolean getFlag(String key)
Retrieve the flag for the given property key.

Parameters:
  `key` - the property key
Returns:
  `true` if the property is set to the string "true" (ignoring case), false otherwise

### checkFlag

@Nullable public static Boolean checkFlag(String key)
Retrieve the flag for the given property key, returning `null` instead of `false` in case of no actual flag set.

Parameters:
  `key` - the property key
Returns:
  `true` if the property is set to the string "true" (ignoring case), false if it is set to any other value, `null` if it is not set at all
Since:
  6.2.6