Class JsonPropertySourceFactory
- java.lang.Object
-
- io.microsphere.spring.config.env.support.JsonPropertySourceFactory
-
- All Implemented Interfaces:
org.springframework.core.io.support.PropertySourceFactory
public class JsonPropertySourceFactory extends java.lang.Object implements org.springframework.core.io.support.PropertySourceFactory
PropertySourceFactory
implementation that createsPropertySource
instances from JSON resources.This class reads JSON content and converts it into a
MapPropertySource
, allowing the properties defined in the JSON resource to be easily integrated into the Spring environment.Example Usage
Suppose you have a JSON resource with the following content:{ "app": { "name": "My Application", "version": "1.0.0" } }
You can use this factory to load the JSON file as a property source:
EncodedResource encodedResource = new EncodedResource(resource); PropertySource propertySource = jsonPropertySourceFactory.createPropertySource("jsonProperties", encodedResource); environment.getPropertySources().addLast(propertySource);
After adding the property source to the environment, you can access properties like:
environment.getProperty("app.name")
which returns "My Application"environment.getProperty("app.version")
which returns "1.0.0"
- Since:
- 1.0.0
- Author:
- Mercy
- See Also:
JsonPropertySource
,PropertySourceFactory
,PropertySource
,MapPropertySource
-
-
Constructor Summary
Constructors Constructor Description JsonPropertySourceFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.springframework.core.env.PropertySource<?>
createPropertySource(java.lang.String name, org.springframework.core.io.support.EncodedResource resource)
-
-
-
Method Detail
-
createPropertySource
public org.springframework.core.env.PropertySource<?> createPropertySource(java.lang.String name, org.springframework.core.io.support.EncodedResource resource) throws java.io.IOException
- Specified by:
createPropertySource
in interfaceorg.springframework.core.io.support.PropertySourceFactory
- Throws:
java.io.IOException
-
-