Polishing

This commit is contained in:
Sam Brannen
2024-05-22 15:09:54 +02:00
parent 1bc71824ea
commit bc291949c2
2 changed files with 14 additions and 10 deletions

View File

@@ -45,6 +45,8 @@ import org.springframework.util.ReflectionUtils;
* @author Sam Brannen
* @since 5.2.5
* @see DynamicPropertiesContextCustomizerFactory
* @see DefaultDynamicPropertyRegistry
* @see DynamicPropertySourceBeanInitializer
*/
class DynamicPropertiesContextCustomizer implements ContextCustomizer {
@@ -59,20 +61,11 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer {
DynamicPropertiesContextCustomizer(Set<Method> methods) {
methods.forEach(this::assertValid);
methods.forEach(DynamicPropertiesContextCustomizer::assertValid);
this.methods = methods;
}
private void assertValid(Method method) {
Assert.state(Modifier.isStatic(method.getModifiers()),
() -> "@DynamicPropertySource method '" + method.getName() + "' must be static");
Class<?>[] types = method.getParameterTypes();
Assert.state(types.length == 1 && types[0] == DynamicPropertyRegistry.class,
() -> "@DynamicPropertySource method '" + method.getName() +
"' must accept a single DynamicPropertyRegistry argument");
}
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
ConfigurableEnvironment environment = context.getEnvironment();
@@ -115,4 +108,14 @@ class DynamicPropertiesContextCustomizer implements ContextCustomizer {
return this.methods.hashCode();
}
private static void assertValid(Method method) {
Assert.state(Modifier.isStatic(method.getModifiers()),
() -> "@DynamicPropertySource method '" + method.getName() + "' must be static");
Class<?>[] types = method.getParameterTypes();
Assert.state(types.length == 1 && types[0] == DynamicPropertyRegistry.class,
() -> "@DynamicPropertySource method '" + method.getName() +
"' must accept a single DynamicPropertyRegistry argument");
}
}

View File

@@ -41,6 +41,7 @@ class DynamicValuesPropertySource extends MapPropertySource {
super(PROPERTY_SOURCE_NAME, Collections.unmodifiableMap(valueSuppliers));
}
@Override
@Nullable
public Object getProperty(String name) {