49
49
*/
50
50
public class PropertySourceProcessor {
51
51
52
- private static final PropertySourceFactory DEFAULT_PROPERTY_SOURCE_FACTORY = new DefaultPropertySourceFactory ();
52
+ private static final PropertySourceFactory defaultPropertySourceFactory = new DefaultPropertySourceFactory ();
53
53
54
54
private static final Log logger = LogFactory .getLog (PropertySourceProcessor .class );
55
55
56
+
56
57
private final ConfigurableEnvironment environment ;
57
58
58
59
private final ResourceLoader resourceLoader ;
59
60
60
- private final List <String > propertySourceNames ;
61
+ private final List <String > propertySourceNames = new ArrayList <>();
62
+
61
63
62
64
public PropertySourceProcessor (ConfigurableEnvironment environment , ResourceLoader resourceLoader ) {
63
65
this .environment = environment ;
64
66
this .resourceLoader = resourceLoader ;
65
- this .propertySourceNames = new ArrayList <>();
66
67
}
67
68
69
+
68
70
/**
69
71
* Process the specified {@link PropertySourceDescriptor} against the
70
72
* environment managed by this instance.
@@ -78,7 +80,7 @@ public void processPropertySource(PropertySourceDescriptor descriptor) throws IO
78
80
Assert .isTrue (locations .size () > 0 , "At least one @PropertySource(value) location is required" );
79
81
boolean ignoreResourceNotFound = descriptor .ignoreResourceNotFound ();
80
82
PropertySourceFactory factory = (descriptor .propertySourceFactory () != null ?
81
- instantiateClass (descriptor .propertySourceFactory ()) : DEFAULT_PROPERTY_SOURCE_FACTORY );
83
+ instantiateClass (descriptor .propertySourceFactory ()) : defaultPropertySourceFactory );
82
84
83
85
for (String location : locations ) {
84
86
try {
@@ -100,13 +102,13 @@ public void processPropertySource(PropertySourceDescriptor descriptor) throws IO
100
102
}
101
103
}
102
104
103
- private void addPropertySource (org . springframework . core . env . PropertySource <?> propertySource ) {
105
+ private void addPropertySource (PropertySource <?> propertySource ) {
104
106
String name = propertySource .getName ();
105
107
MutablePropertySources propertySources = this .environment .getPropertySources ();
106
108
107
109
if (this .propertySourceNames .contains (name )) {
108
110
// We've already added a version, we need to extend it
109
- org . springframework . core . env . PropertySource <?> existing = propertySources .get (name );
111
+ PropertySource <?> existing = propertySources .get (name );
110
112
if (existing != null ) {
111
113
PropertySource <?> newSource = (propertySource instanceof ResourcePropertySource rps ?
112
114
rps .withResourceName () : propertySource );
@@ -136,7 +138,8 @@ private void addPropertySource(org.springframework.core.env.PropertySource<?> pr
136
138
this .propertySourceNames .add (name );
137
139
}
138
140
139
- private PropertySourceFactory instantiateClass (Class <? extends PropertySourceFactory > type ) {
141
+
142
+ private static PropertySourceFactory instantiateClass (Class <? extends PropertySourceFactory > type ) {
140
143
try {
141
144
Constructor <? extends PropertySourceFactory > constructor = type .getDeclaredConstructor ();
142
145
ReflectionUtils .makeAccessible (constructor );
0 commit comments