类 TestPropertySourceUtils
- java.lang.Object
- org.springframework.test.context.support.TestPropertySourceUtils
public abstract class TestPropertySourceUtils extends Object
Utility methods for working with@TestPropertySource
and adding testPropertySources
to theEnvironment
.Primarily intended for use within the framework.
- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen
- 另请参阅:
TestPropertySource
字段概要
字段 修饰符和类型 字段 说明 static String
INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
The name of theMapPropertySource
created from inlined properties.
构造器概要
构造器 构造器 说明 TestPropertySourceUtils()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static void
addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties)
Add the given inlined properties to theEnvironment
of the suppliedcontext
.static void
addInlinedPropertiesToEnvironment(ConfigurableEnvironment environment, String... inlinedProperties)
Add the given inlined properties (in the form of key-value pairs) to the suppliedenvironment
.static void
addPropertiesFilesToEnvironment(ConfigurableApplicationContext context, String... locations)
Add theProperties
files from the given resourcelocations
to theEnvironment
of the suppliedcontext
.static void
addPropertiesFilesToEnvironment(ConfigurableEnvironment environment, ResourceLoader resourceLoader, String... locations)
static Map<String,Object>
convertInlinedPropertiesToMap(String... inlinedProperties)
Convert the supplied inlined properties (in the form of key-value pairs) into a map keyed by property name, preserving the ordering of property names in the returned map.
字段详细资料
INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
public static final String INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
The name of theMapPropertySource
created from inlined properties.
构造器详细资料
TestPropertySourceUtils
public TestPropertySourceUtils()
方法详细资料
addPropertiesFilesToEnvironment
public static void addPropertiesFilesToEnvironment(ConfigurableApplicationContext context, String... locations)
Add theProperties
files from the given resourcelocations
to theEnvironment
of the suppliedcontext
.This method simply delegates to
addPropertiesFilesToEnvironment(ConfigurableEnvironment, ResourceLoader, String...)
.- 参数:
context
- the application context whose environment should be updated; nevernull
locations
- the resource locations ofProperties
files to add to the environment; potentially empty but nevernull
- 抛出:
IllegalStateException
- if an error occurs while processing a properties file- 从以下版本开始:
- 4.1.5
- 另请参阅:
ResourcePropertySource
,TestPropertySource.locations()
,addPropertiesFilesToEnvironment(ConfigurableEnvironment, ResourceLoader, String...)
addPropertiesFilesToEnvironment
public static void addPropertiesFilesToEnvironment(ConfigurableEnvironment environment, ResourceLoader resourceLoader, String... locations)
Add theProperties
files from the given resourcelocations
to the suppliedenvironment
.Property placeholders in resource locations (i.e.,
${...}
) will be resolved against theEnvironment
.Each properties file will be converted to a
ResourcePropertySource
that will be added to thePropertySources
of the environment with highest precedence.- 参数:
environment
- the environment to update; nevernull
resourceLoader
- theResourceLoader
to use to load each resource; nevernull
locations
- the resource locations ofProperties
files to add to the environment; potentially empty but nevernull
- 抛出:
IllegalStateException
- if an error occurs while processing a properties file- 从以下版本开始:
- 4.3
- 另请参阅:
ResourcePropertySource
,TestPropertySource.locations()
,addPropertiesFilesToEnvironment(ConfigurableApplicationContext, String...)
addInlinedPropertiesToEnvironment
public static void addInlinedPropertiesToEnvironment(ConfigurableApplicationContext context, String... inlinedProperties)
Add the given inlined properties to theEnvironment
of the suppliedcontext
.This method simply delegates to
addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
.- 参数:
context
- the application context whose environment should be updated; nevernull
inlinedProperties
- the inlined properties to add to the environment; potentially empty but nevernull
- 从以下版本开始:
- 4.1.5
- 另请参阅:
TestPropertySource.properties()
,addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])
addInlinedPropertiesToEnvironment
public static void addInlinedPropertiesToEnvironment(ConfigurableEnvironment environment, String... inlinedProperties)
Add the given inlined properties (in the form of key-value pairs) to the suppliedenvironment
.All key-value pairs will be added to the
Environment
as a singleMapPropertySource
with the highest precedence.For details on the parsing of inlined properties, consult the Javadoc for
convertInlinedPropertiesToMap(java.lang.String...)
.- 参数:
environment
- the environment to update; nevernull
inlinedProperties
- the inlined properties to add to the environment; potentially empty but nevernull
- 从以下版本开始:
- 4.1.5
- 另请参阅:
MapPropertySource
,INLINED_PROPERTIES_PROPERTY_SOURCE_NAME
,TestPropertySource.properties()
,convertInlinedPropertiesToMap(java.lang.String...)
convertInlinedPropertiesToMap
public static Map<String,Object> convertInlinedPropertiesToMap(String... inlinedProperties)
Convert the supplied inlined properties (in the form of key-value pairs) into a map keyed by property name, preserving the ordering of property names in the returned map.Parsing of the key-value pairs is achieved by converting all pairs into virtual properties files in memory and delegating to
Properties.load(java.io.Reader)
to parse each virtual file.For a full discussion of inlined properties, consult the Javadoc for
TestPropertySource.properties()
.- 参数:
inlinedProperties
- the inlined properties to convert; potentially empty but nevernull
- 返回:
- a new, ordered map containing the converted properties
- 抛出:
IllegalStateException
- if a given key-value pair cannot be parsed, or if a given inlined property contains multiple key-value pairs- 从以下版本开始:
- 4.1.5
- 另请参阅:
addInlinedPropertiesToEnvironment(ConfigurableEnvironment, String[])