Polishing
This commit is contained in:
parent
759e3d4aa6
commit
7882d265c6
|
|
@ -674,9 +674,9 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||
|
||||
private void registerRuntimeHints(RuntimeHints hints) {
|
||||
for (PropertySourceDescriptor descriptor : this.descriptors) {
|
||||
Class<?> factory = descriptor.propertySourceFactory();
|
||||
if (factory != null) {
|
||||
hints.reflection().registerType(factory, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
Class<?> factoryClass = descriptor.propertySourceFactory();
|
||||
if (factoryClass != null) {
|
||||
hints.reflection().registerType(factoryClass, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
}
|
||||
for (String location : descriptor.locations()) {
|
||||
Resource resource = this.resourceResolver.apply(location);
|
||||
|
|
|
|||
|
|
@ -18,9 +18,14 @@ package org.springframework.test.context.aot;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.aot.hint.ResourceHints;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PropertySourceDescriptor;
|
||||
import org.springframework.test.context.ContextLoader;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
|
@ -68,8 +73,10 @@ class MergedContextConfigurationRuntimeHints {
|
|||
// @ContextConfiguration(locations = ...)
|
||||
registerClasspathResources(mergedConfig.getLocations(), runtimeHints, classLoader);
|
||||
|
||||
// @TestPropertySource(locations = ... )
|
||||
registerClasspathResources(mergedConfig.getPropertySourceLocations(), runtimeHints, classLoader);
|
||||
for (PropertySourceDescriptor descriptor : mergedConfig.getPropertySourceDescriptors()) {
|
||||
// @TestPropertySource(locations = ...)
|
||||
registerClasspathResources(descriptor.locations().stream(), runtimeHints, classLoader);
|
||||
}
|
||||
|
||||
// @WebAppConfiguration(value = ...)
|
||||
if (webMergedContextConfigurationClass.isInstance(mergedConfig)) {
|
||||
|
|
@ -89,12 +96,17 @@ class MergedContextConfigurationRuntimeHints {
|
|||
runtimeHints.reflection().registerType(type, INVOKE_DECLARED_CONSTRUCTORS);
|
||||
}
|
||||
|
||||
private void registerClasspathResources(String[] paths, RuntimeHints runtimeHints, ClassLoader classLoader) {
|
||||
private void registerClasspathResources(String[] locations, RuntimeHints runtimeHints, ClassLoader classLoader) {
|
||||
registerClasspathResources(Arrays.stream(locations), runtimeHints, classLoader);
|
||||
}
|
||||
|
||||
private void registerClasspathResources(Stream<String> locations, RuntimeHints runtimeHints, ClassLoader classLoader) {
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader(classLoader);
|
||||
Arrays.stream(paths)
|
||||
.filter(path -> path.startsWith(CLASSPATH_URL_PREFIX))
|
||||
.map(resourceLoader::getResource)
|
||||
.forEach(runtimeHints.resources()::registerResource);
|
||||
ResourceHints resourceHints = runtimeHints.resources();
|
||||
locations.map(resourceLoader::getResource)
|
||||
.filter(ClassPathResource.class::isInstance)
|
||||
.filter(Resource::exists)
|
||||
.forEach(resourceHints::registerResource);
|
||||
}
|
||||
|
||||
private void registerClasspathResourceDirectoryStructure(String directory, RuntimeHints runtimeHints) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* Uses configuration identical to {@link BasicSpringJupiterTests}.
|
||||
*
|
||||
* <p>NOTE: if you modify the configuration for this test class, you must also
|
||||
* modify the configuration for {@link BasicSpringJupiterTests} accordingly.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.0
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS;
|
||||
|
||||
/**
|
||||
* Uses configuration identical to {@link BasicSpringJupiterSharedConfigTests}.
|
||||
*
|
||||
* <p>NOTE: if you modify the configuration for this test class, you must also
|
||||
* modify the configuration for {@link BasicSpringJupiterSharedConfigTests}
|
||||
* accordingly.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.0
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue