@@ -109,48 +109,51 @@ public ApplicationContext loadContext(MergedContextConfiguration mergedContextCo
109
109
mergedContextConfiguration = replaceIfNecessary (mergedContextConfiguration );
110
110
synchronized (this .contextCache ) {
111
111
ApplicationContext context = this .contextCache .get (mergedContextConfiguration );
112
- if (context == null ) {
113
- try {
114
- if (mergedContextConfiguration instanceof AotMergedContextConfiguration aotMergedConfig ) {
115
- context = loadContextInAotMode (aotMergedConfig );
116
- }
117
- else {
118
- context = loadContextInternal (mergedContextConfiguration );
119
- }
120
- if (logger .isTraceEnabled ()) {
121
- logger .trace ("Storing ApplicationContext [%s] in cache under key %s" .formatted (
122
- System .identityHashCode (context ), mergedContextConfiguration ));
112
+ try {
113
+ if (context == null ) {
114
+ try {
115
+ if (mergedContextConfiguration instanceof AotMergedContextConfiguration aotMergedConfig ) {
116
+ context = loadContextInAotMode (aotMergedConfig );
117
+ }
118
+ else {
119
+ context = loadContextInternal (mergedContextConfiguration );
120
+ }
121
+ if (logger .isTraceEnabled ()) {
122
+ logger .trace ("Storing ApplicationContext [%s] in cache under key %s" .formatted (
123
+ System .identityHashCode (context ), mergedContextConfiguration ));
124
+ }
125
+ this .contextCache .put (mergedContextConfiguration , context );
123
126
}
124
- this .contextCache .put (mergedContextConfiguration , context );
125
- }
126
- catch (Exception ex ) {
127
- Throwable cause = ex ;
128
- if (ex instanceof ContextLoadException cle ) {
129
- cause = cle .getCause ();
130
- for (ApplicationContextFailureProcessor contextFailureProcessor : this .contextFailureProcessors ) {
131
- try {
132
- contextFailureProcessor .processLoadFailure (cle .getApplicationContext (), cause );
133
- }
134
- catch (Throwable throwable ) {
135
- if (logger .isDebugEnabled ()) {
136
- logger .debug ("Ignoring exception thrown from ApplicationContextFailureProcessor [%s]: %s"
137
- .formatted (contextFailureProcessor , throwable ));
127
+ catch (Exception ex ) {
128
+ Throwable cause = ex ;
129
+ if (ex instanceof ContextLoadException cle ) {
130
+ cause = cle .getCause ();
131
+ for (ApplicationContextFailureProcessor contextFailureProcessor : this .contextFailureProcessors ) {
132
+ try {
133
+ contextFailureProcessor .processLoadFailure (cle .getApplicationContext (), cause );
134
+ }
135
+ catch (Throwable throwable ) {
136
+ if (logger .isDebugEnabled ()) {
137
+ logger .debug ("Ignoring exception thrown from ApplicationContextFailureProcessor [%s]: %s"
138
+ .formatted (contextFailureProcessor , throwable ));
139
+ }
138
140
}
139
141
}
140
142
}
143
+ throw new IllegalStateException (
144
+ "Failed to load ApplicationContext for " + mergedContextConfiguration , cause );
141
145
}
142
- throw new IllegalStateException (
143
- "Failed to load ApplicationContext for " + mergedContextConfiguration , cause );
144
146
}
145
- }
146
- else {
147
- if ( logger .isTraceEnabled ()) {
148
- logger . trace ( "Retrieved ApplicationContext [%s] from cache with key %s" . formatted (
149
- System . identityHashCode ( context ), mergedContextConfiguration ));
147
+ else {
148
+ if ( logger . isTraceEnabled ()) {
149
+ logger .trace ( "Retrieved ApplicationContext [%s] from cache with key %s" . formatted (
150
+ System . identityHashCode ( context ), mergedContextConfiguration ));
151
+ }
150
152
}
151
153
}
152
-
153
- this .contextCache .logStatistics ();
154
+ finally {
155
+ this .contextCache .logStatistics ();
156
+ }
154
157
155
158
return context ;
156
159
}
0 commit comments