This commit is contained in:
Phillip Webb 2024-04-04 20:14:01 -07:00
parent e2ec066fcf
commit 21f5d375b7
4 changed files with 10 additions and 29 deletions

View File

@ -122,28 +122,11 @@ public class ConnectionDetailsFactories {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <S, D extends ConnectionDetails> Registration<S, D> get(ConnectionDetailsFactory<S, D> factory) { private static <S, D extends ConnectionDetails> Registration<S, D> get(ConnectionDetailsFactory<S, D> factory) {
ResolvableType type = ResolvableType.forClass(ConnectionDetailsFactory.class, factory.getClass()); ResolvableType type = ResolvableType.forClass(ConnectionDetailsFactory.class, factory.getClass());
Class<?>[] generics = resolveGenerics(type); Class<?>[] generics = type.resolveGenerics();
if (generics != null) { Class<S> sourceType = (Class<S>) generics[0];
return new Registration<>((Class<S>) generics[0], (Class<D>) generics[1], factory); Class<D> connectionDetailsType = (Class<D>) generics[1];
} return (sourceType != null && connectionDetailsType != null)
return null; ? new Registration<>(sourceType, connectionDetailsType, factory) : null;
}
/**
* Resolve the generics of the given {@link ResolvableType} or {@code null} if any
* of them cannot be resolved.
* @param type the type to inspect
* @return the resolved generics if they can be loaded from the classpath,
* {@code null} otherwise
*/
private static Class<?>[] resolveGenerics(ResolvableType type) {
Class<?>[] resolvedGenerics = type.resolveGenerics();
for (Class<?> genericRawType : resolvedGenerics) {
if (genericRawType == null) {
return null;
}
}
return resolvedGenerics;
} }
} }

View File

@ -97,11 +97,11 @@ class SpringApplicationBannerPrinter {
private String createStringFromBanner(Banner banner, Environment environment, Class<?> mainApplicationClass) private String createStringFromBanner(Banner banner, Environment environment, Class<?> mainApplicationClass)
throws UnsupportedEncodingException { throws UnsupportedEncodingException {
String charset = environment.getProperty("spring.banner.charset", StandardCharsets.UTF_8.name()); String charset = environment.getProperty("spring.banner.charset", StandardCharsets.UTF_8.name());
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (PrintStream printStream = new PrintStream(baos, false, charset)) { try (PrintStream out = new PrintStream(byteArrayOutputStream, false, charset)) {
banner.printBanner(environment, mainApplicationClass, printStream); banner.printBanner(environment, mainApplicationClass, out);
} }
return baos.toString(charset); return byteArrayOutputStream.toString(charset);
} }
/** /**

View File

@ -62,8 +62,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
ConfigurationProperty property = source.getConfigurationProperty(name); ConfigurationProperty property = source.getConfigurationProperty(name);
if (property != null && !hasDescendants) { if (property != null && !hasDescendants) {
getContext().setConfigurationProperty(property); getContext().setConfigurationProperty(property);
Object result = property.getValue(); Object result = getContext().getPlaceholdersResolver().resolvePlaceholders(property.getValue());
result = getContext().getPlaceholdersResolver().resolvePlaceholders(result);
return getContext().getConverter().convert(result, target); return getContext().getConverter().convert(result, target);
} }
source = source.filter(name::isAncestorOf); source = source.filter(name::isAncestorOf);

View File

@ -104,7 +104,6 @@ final class GracefulShutdown {
} }
} }
} }
} }
catch (InterruptedException ex) { catch (InterruptedException ex) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();