|
|
|
@ -135,56 +135,59 @@ public class DefaultCacheAwareContextLoaderDelegate implements CacheAwareContext |
|
|
|
mergedConfig = replaceIfNecessary(mergedConfig); |
|
|
|
mergedConfig = replaceIfNecessary(mergedConfig); |
|
|
|
synchronized (this.contextCache) { |
|
|
|
synchronized (this.contextCache) { |
|
|
|
ApplicationContext context = this.contextCache.get(mergedConfig); |
|
|
|
ApplicationContext context = this.contextCache.get(mergedConfig); |
|
|
|
if (context == null) { |
|
|
|
try { |
|
|
|
Integer failureCount = this.contextCache.getFailureCount(mergedConfig); |
|
|
|
if (context == null) { |
|
|
|
if (failureCount >= this.failureThreshold) { |
|
|
|
Integer failureCount = this.contextCache.getFailureCount(mergedConfig); |
|
|
|
throw new IllegalStateException(""" |
|
|
|
if (failureCount >= this.failureThreshold) { |
|
|
|
ApplicationContext failure threshold (%d) exceeded: \ |
|
|
|
throw new IllegalStateException(""" |
|
|
|
skipping repeated attempt to load context for %s""" |
|
|
|
ApplicationContext failure threshold (%d) exceeded: \ |
|
|
|
.formatted(this.failureThreshold, mergedConfig)); |
|
|
|
skipping repeated attempt to load context for %s""" |
|
|
|
} |
|
|
|
.formatted(this.failureThreshold, mergedConfig)); |
|
|
|
try { |
|
|
|
|
|
|
|
if (mergedConfig instanceof AotMergedContextConfiguration aotMergedConfig) { |
|
|
|
|
|
|
|
context = loadContextInAotMode(aotMergedConfig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
context = loadContextInternal(mergedConfig); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
try { |
|
|
|
logger.trace("Storing ApplicationContext [%s] in cache under key %s".formatted( |
|
|
|
if (mergedConfig instanceof AotMergedContextConfiguration aotMergedConfig) { |
|
|
|
System.identityHashCode(context), mergedConfig)); |
|
|
|
context = loadContextInAotMode(aotMergedConfig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
context = loadContextInternal(mergedConfig); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
|
|
|
|
logger.trace("Storing ApplicationContext [%s] in cache under key %s".formatted( |
|
|
|
|
|
|
|
System.identityHashCode(context), mergedConfig)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.contextCache.put(mergedConfig, context); |
|
|
|
} |
|
|
|
} |
|
|
|
this.contextCache.put(mergedConfig, context); |
|
|
|
catch (Exception ex) { |
|
|
|
} |
|
|
|
this.contextCache.incrementFailureCount(mergedConfig); |
|
|
|
catch (Exception ex) { |
|
|
|
Throwable cause = ex; |
|
|
|
this.contextCache.incrementFailureCount(mergedConfig); |
|
|
|
if (ex instanceof ContextLoadException cle) { |
|
|
|
Throwable cause = ex; |
|
|
|
cause = cle.getCause(); |
|
|
|
if (ex instanceof ContextLoadException cle) { |
|
|
|
for (ApplicationContextFailureProcessor contextFailureProcessor : this.contextFailureProcessors) { |
|
|
|
cause = cle.getCause(); |
|
|
|
try { |
|
|
|
for (ApplicationContextFailureProcessor contextFailureProcessor : this.contextFailureProcessors) { |
|
|
|
contextFailureProcessor.processLoadFailure(cle.getApplicationContext(), cause); |
|
|
|
try { |
|
|
|
} |
|
|
|
contextFailureProcessor.processLoadFailure(cle.getApplicationContext(), cause); |
|
|
|
catch (Throwable throwable) { |
|
|
|
} |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
catch (Throwable throwable) { |
|
|
|
logger.debug("Ignoring exception thrown from ApplicationContextFailureProcessor [%s]: %s" |
|
|
|
if (logger.isDebugEnabled()) { |
|
|
|
.formatted(contextFailureProcessor, throwable)); |
|
|
|
logger.debug("Ignoring exception thrown from ApplicationContextFailureProcessor [%s]: %s" |
|
|
|
} |
|
|
|
.formatted(contextFailureProcessor, throwable)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
throw new IllegalStateException( |
|
|
|
|
|
|
|
"Failed to load ApplicationContext for " + mergedConfig, cause); |
|
|
|
} |
|
|
|
} |
|
|
|
throw new IllegalStateException( |
|
|
|
|
|
|
|
"Failed to load ApplicationContext for " + mergedConfig, cause); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
if (logger.isTraceEnabled()) { |
|
|
|
logger.trace("Retrieved ApplicationContext [%s] from cache with key %s".formatted( |
|
|
|
logger.trace("Retrieved ApplicationContext [%s] from cache with key %s".formatted( |
|
|
|
System.identityHashCode(context), mergedConfig)); |
|
|
|
System.identityHashCode(context), mergedConfig)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
finally { |
|
|
|
this.contextCache.logStatistics(); |
|
|
|
this.contextCache.logStatistics(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return context; |
|
|
|
return context; |
|
|
|
} |
|
|
|
} |
|
|
|
|