Merge branch '6.2.x'
This commit is contained in:
@@ -92,6 +92,12 @@ the repeated JNDI lookup overhead. See
|
||||
{spring-framework-api}++/jndi/JndiLocatorDelegate.html#IGNORE_JNDI_PROPERTY_NAME++[`JndiLocatorDelegate`]
|
||||
for details.
|
||||
|
||||
| `spring.locking.strict`
|
||||
| Instructs Spring to enforce strict locking during bean creation, rather than the mix of
|
||||
strict and lenient locking that 6.2 applies by default. See
|
||||
{spring-framework-api}++/beans/factory/support/DefaultListableBeanFactory.html#STRICT_LOCKING_PROPERTY_NAME++[`DefaultListableBeanFactory`]
|
||||
for details.
|
||||
|
||||
| `spring.objenesis.ignore`
|
||||
| Instructs Spring to ignore Objenesis, not even attempting to use it. See
|
||||
{spring-framework-api}++/objenesis/SpringObjenesis.html#IGNORE_OBJENESIS_PROPERTY_NAME++[`SpringObjenesis`]
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.aop.AopInvocationException;
|
||||
import org.springframework.aop.RawTargetAccess;
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.cglib.core.ClassLoaderAwareGeneratorStrategy;
|
||||
import org.springframework.cglib.core.CodeGenerationException;
|
||||
import org.springframework.cglib.core.GeneratorStrategy;
|
||||
@@ -203,7 +204,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
enhancer.setSuperclass(proxySuperClass);
|
||||
enhancer.setInterfaces(AopProxyUtils.completeProxiedInterfaces(this.advised));
|
||||
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
||||
enhancer.setAttemptLoad(true);
|
||||
enhancer.setAttemptLoad(enhancer.getUseCache() && AotDetector.useGeneratedArtifacts());
|
||||
enhancer.setStrategy(KotlinDetector.isKotlinType(proxySuperClass) ?
|
||||
new ClassLoaderAwareGeneratorStrategy(classLoader) :
|
||||
new ClassLoaderAwareGeneratorStrategy(classLoader, undeclaredThrowableStrategy)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.beans.BeanInstantiationException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -153,7 +154,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
|
||||
Enhancer enhancer = new Enhancer();
|
||||
enhancer.setSuperclass(beanDefinition.getBeanClass());
|
||||
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
||||
enhancer.setAttemptLoad(true);
|
||||
enhancer.setAttemptLoad(AotDetector.useGeneratedArtifacts());
|
||||
if (this.owner instanceof ConfigurableBeanFactory cbf) {
|
||||
ClassLoader cl = cbf.getBeanClassLoader();
|
||||
enhancer.setStrategy(new ClassLoaderAwareGeneratorStrategy(cl));
|
||||
|
||||
@@ -130,7 +130,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable {
|
||||
|
||||
/**
|
||||
* System property that instructs Spring to enforce string locking during bean creation,
|
||||
* System property that instructs Spring to enforce strict locking during bean creation,
|
||||
* rather than the mix of strict and lenient locking that 6.2 applies by default. Setting
|
||||
* this flag to "true" restores 6.1.x style locking in the entire pre-instantiation phase.
|
||||
* @since 6.2.6
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.aop.scope.ScopedProxyFactoryBean;
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.asm.Opcodes;
|
||||
import org.springframework.asm.Type;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
@@ -138,26 +139,22 @@ class ConfigurationClassEnhancer {
|
||||
Enhancer enhancer = new Enhancer();
|
||||
if (classLoader != null) {
|
||||
enhancer.setClassLoader(classLoader);
|
||||
if (classLoader instanceof SmartClassLoader smartClassLoader &&
|
||||
smartClassLoader.isClassReloadable(configSuperClass)) {
|
||||
enhancer.setUseCache(false);
|
||||
}
|
||||
}
|
||||
enhancer.setSuperclass(configSuperClass);
|
||||
enhancer.setInterfaces(new Class<?>[] {EnhancedConfiguration.class});
|
||||
enhancer.setUseFactory(false);
|
||||
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
||||
enhancer.setAttemptLoad(!isClassReloadable(configSuperClass, classLoader));
|
||||
enhancer.setAttemptLoad(enhancer.getUseCache() && AotDetector.useGeneratedArtifacts());
|
||||
enhancer.setStrategy(new BeanFactoryAwareGeneratorStrategy(classLoader));
|
||||
enhancer.setCallbackFilter(CALLBACK_FILTER);
|
||||
enhancer.setCallbackTypes(CALLBACK_FILTER.getCallbackTypes());
|
||||
return enhancer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given configuration class is reloadable.
|
||||
*/
|
||||
private boolean isClassReloadable(Class<?> configSuperClass, @Nullable ClassLoader classLoader) {
|
||||
return (classLoader instanceof SmartClassLoader smartClassLoader &&
|
||||
smartClassLoader.isClassReloadable(configSuperClass));
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses enhancer to generate a subclass of superclass,
|
||||
* ensuring that callbacks are registered for the new subclass.
|
||||
@@ -545,7 +542,7 @@ class ConfigurationClassEnhancer {
|
||||
Enhancer enhancer = new Enhancer();
|
||||
enhancer.setSuperclass(factoryBean.getClass());
|
||||
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
||||
enhancer.setAttemptLoad(true);
|
||||
enhancer.setAttemptLoad(AotDetector.useGeneratedArtifacts());
|
||||
enhancer.setCallbackType(MethodInterceptor.class);
|
||||
|
||||
// Ideally create enhanced FactoryBean proxy without constructor side effects,
|
||||
|
||||
@@ -76,7 +76,7 @@ class ConfigurationClassEnhancerTests {
|
||||
classLoader = new BasicSmartClassLoader(getClass().getClassLoader());
|
||||
enhancedClass = configurationClassEnhancer.enhance(MyConfigWithPublicClass.class, classLoader);
|
||||
assertThat(MyConfigWithPublicClass.class).isAssignableFrom(enhancedClass);
|
||||
assertThat(enhancedClass.getClassLoader()).isEqualTo(classLoader.getParent());
|
||||
assertThat(enhancedClass.getClassLoader()).isEqualTo(classLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +126,7 @@ class ConfigurationClassEnhancerTests {
|
||||
classLoader = new BasicSmartClassLoader(getClass().getClassLoader());
|
||||
enhancedClass = configurationClassEnhancer.enhance(MyConfigWithNonPublicMethod.class, classLoader);
|
||||
assertThat(MyConfigWithNonPublicMethod.class).isAssignableFrom(enhancedClass);
|
||||
assertThat(enhancedClass.getClassLoader()).isEqualTo(classLoader.getParent());
|
||||
assertThat(enhancedClass.getClassLoader()).isEqualTo(classLoader);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -215,6 +215,8 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class PathMatchingResourcePatternResolver implements ResourcePatternResolver {
|
||||
|
||||
private static final Resource[] EMPTY_RESOURCE_ARRAY = {};
|
||||
|
||||
private static final Log logger = LogFactory.getLog(PathMatchingResourcePatternResolver.class);
|
||||
|
||||
/**
|
||||
@@ -256,6 +258,8 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
|
||||
private PathMatcher pathMatcher = new AntPathMatcher();
|
||||
|
||||
private boolean useCaches = true;
|
||||
|
||||
private final Map<String, Resource[]> rootDirCache = new ConcurrentHashMap<>();
|
||||
|
||||
private final Map<String, NavigableSet<String>> jarEntriesCache = new ConcurrentHashMap<>();
|
||||
@@ -328,6 +332,22 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
return this.pathMatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether this resolver should use jar caches. Default is {@code true}.
|
||||
* <p>Switch this flag to {@code false} in order to avoid any jar caching, at
|
||||
* the {@link JarURLConnection} level as well as within this resolver instance.
|
||||
* <p>Note that {@link JarURLConnection#setDefaultUseCaches} can be turned off
|
||||
* independently. This resolver-level setting is designed to only enforce
|
||||
* {@code JarURLConnection#setUseCaches(false)} if necessary but otherwise
|
||||
* leaves the JVM-level default in place.
|
||||
* @since 6.1.19
|
||||
* @see JarURLConnection#setUseCaches
|
||||
* @see #clearCache()
|
||||
*/
|
||||
public void setUseCaches(boolean useCaches) {
|
||||
this.useCaches = useCaches;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Resource getResource(String location) {
|
||||
@@ -351,7 +371,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
// all class path resources with the given name
|
||||
Collections.addAll(resources, findAllClassPathResources(locationPatternWithoutPrefix));
|
||||
}
|
||||
return resources.toArray(new Resource[0]);
|
||||
return resources.toArray(EMPTY_RESOURCE_ARRAY);
|
||||
}
|
||||
else {
|
||||
// Generally only look for a pattern after a prefix here,
|
||||
@@ -395,7 +415,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Resolved class path location [" + path + "] to resources " + result);
|
||||
}
|
||||
return result.toArray(new Resource[0]);
|
||||
return result.toArray(EMPTY_RESOURCE_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -532,7 +552,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
Set<ClassPathManifestEntry> entries = this.manifestEntriesCache;
|
||||
if (entries == null) {
|
||||
entries = getClassPathManifestEntries();
|
||||
this.manifestEntriesCache = entries;
|
||||
if (this.useCaches) {
|
||||
this.manifestEntriesCache = entries;
|
||||
}
|
||||
}
|
||||
for (ClassPathManifestEntry entry : entries) {
|
||||
if (!result.contains(entry.resource()) &&
|
||||
@@ -684,7 +706,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
if (rootDirResources == null) {
|
||||
// Lookup for specific directory, creating a cache entry for it.
|
||||
rootDirResources = getResources(rootDirPath);
|
||||
this.rootDirCache.put(rootDirPath, rootDirResources);
|
||||
if (this.useCaches) {
|
||||
this.rootDirCache.put(rootDirPath, rootDirResources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -716,7 +740,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Resolved location pattern [" + locationPattern + "] to resources " + result);
|
||||
}
|
||||
return result.toArray(new Resource[0]);
|
||||
return result.toArray(EMPTY_RESOURCE_ARRAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -837,6 +861,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
|
||||
if (con instanceof JarURLConnection jarCon) {
|
||||
// Should usually be the case for traditional JAR files.
|
||||
if (!this.useCaches) {
|
||||
jarCon.setUseCaches(false);
|
||||
}
|
||||
try {
|
||||
jarFile = jarCon.getJarFile();
|
||||
jarFileUrl = jarCon.getJarFileURL().toExternalForm();
|
||||
@@ -900,8 +927,10 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
|
||||
}
|
||||
}
|
||||
}
|
||||
// Cache jar entries in TreeSet for efficient searching on re-encounter.
|
||||
this.jarEntriesCache.put(jarFileUrl, entriesCache);
|
||||
if (this.useCaches) {
|
||||
// Cache jar entries in TreeSet for efficient searching on re-encounter.
|
||||
this.jarEntriesCache.put(jarFileUrl, entriesCache);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -132,6 +132,7 @@ class PathMatchingResourcePatternResolverTests {
|
||||
Path rootDir = Paths.get("src/test/resources/custom%23root").toAbsolutePath();
|
||||
URL root = new URL("file:" + rootDir + "/");
|
||||
resolver = new PathMatchingResourcePatternResolver(new DefaultResourceLoader(new URLClassLoader(new URL[] {root})));
|
||||
resolver.setUseCaches(false);
|
||||
assertExactFilenames("classpath*:scanned/*.txt", "resource#test1.txt", "resource#test2.txt");
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.cglib.core.SpringNamingPolicy;
|
||||
@@ -788,7 +789,7 @@ public class MvcUriComponentsBuilder {
|
||||
enhancer.setSuperclass(controllerType);
|
||||
enhancer.setInterfaces(new Class<?>[] {MethodInvocationInfo.class});
|
||||
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
||||
enhancer.setAttemptLoad(true);
|
||||
enhancer.setAttemptLoad(AotDetector.useGeneratedArtifacts());
|
||||
enhancer.setCallbackType(MethodInterceptor.class);
|
||||
|
||||
Class<?> proxyClass = enhancer.createClass();
|
||||
|
||||
Reference in New Issue
Block a user