• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

TAKETODAY / today-infrastructure / 18227001691

03 Oct 2025 03:44PM UTC coverage: 81.889% (+0.004%) from 81.885%
18227001691

push

github

TAKETODAY
:white_check_mark:

59822 of 78041 branches covered (76.65%)

Branch coverage included in aggregate %.

141269 of 167523 relevant lines covered (84.33%)

3.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.37
today-context/src/main/java/infra/context/annotation/ConfigurationClassBeanDefinitionReader.java
1
/*
2
 * Copyright 2017 - 2025 the original author or authors.
3
 *
4
 * This program is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see [https://www.gnu.org/licenses/]
16
 */
17

18
package infra.context.annotation;
19

20
import org.jspecify.annotations.Nullable;
21

22
import java.io.Serial;
23
import java.lang.reflect.Method;
24
import java.util.HashMap;
25
import java.util.Map;
26
import java.util.Set;
27

28
import infra.beans.factory.BeanDefinitionStoreException;
29
import infra.beans.factory.BeanRegistrar;
30
import infra.beans.factory.annotation.AnnotatedBeanDefinition;
31
import infra.beans.factory.annotation.AnnotatedGenericBeanDefinition;
32
import infra.beans.factory.annotation.DisableAllDependencyInjection;
33
import infra.beans.factory.annotation.DisableDependencyInjection;
34
import infra.beans.factory.annotation.EnableDependencyInjection;
35
import infra.beans.factory.config.BeanDefinition;
36
import infra.beans.factory.config.BeanDefinitionHolder;
37
import infra.beans.factory.support.AbstractBeanDefinition;
38
import infra.beans.factory.support.AbstractBeanDefinitionReader;
39
import infra.beans.factory.support.BeanDefinitionOverrideException;
40
import infra.beans.factory.support.BeanDefinitionReader;
41
import infra.beans.factory.support.BeanDefinitionRegistry;
42
import infra.beans.factory.support.BeanNameGenerator;
43
import infra.beans.factory.support.BeanRegistryAdapter;
44
import infra.beans.factory.support.RootBeanDefinition;
45
import infra.beans.factory.xml.XmlBeanDefinitionReader;
46
import infra.context.BootstrapContext;
47
import infra.core.annotation.MergedAnnotation;
48
import infra.core.annotation.MergedAnnotations;
49
import infra.core.type.AnnotationMetadata;
50
import infra.core.type.MethodMetadata;
51
import infra.core.type.StandardAnnotationMetadata;
52
import infra.core.type.StandardMethodMetadata;
53
import infra.lang.Assert;
54
import infra.logging.Logger;
55
import infra.logging.LoggerFactory;
56
import infra.stereotype.Component;
57
import infra.util.ObjectUtils;
58
import infra.util.ReflectionUtils;
59
import infra.util.StringUtils;
60

61
/**
62
 * Reads a given fully-populated set of ConfigurationClass instances, registering bean
63
 * definitions with the given {@link BeanDefinitionRegistry} based on its contents.
64
 *
65
 * @author Chris Beams
66
 * @author Juergen Hoeller
67
 * @author Phillip Webb
68
 * @author Sam Brannen
69
 * @author Sebastien Deleuze
70
 * @author <a href="https://github.com/TAKETODAY">Harry Yang</a>
71
 * @see ConfigurationClassParser
72
 * @since 4.0
73
 */
74
class ConfigurationClassBeanDefinitionReader {
75

76
  private static final Logger logger = LoggerFactory.getLogger(ConfigurationClassBeanDefinitionReader.class);
3✔
77

78
  private static final ScopeMetadataResolver scopeMetadataResolver = new AnnotationScopeMetadataResolver();
5✔
79

80
  private final ImportRegistry importRegistry;
81

82
  private final BootstrapContext bootstrapContext;
83

84
  private final BeanNameGenerator importBeanNameGenerator;
85

86
  /**
87
   * Create a new {@link ConfigurationClassBeanDefinitionReader} instance
88
   * that will be used to populate the given {@link BeanDefinitionRegistry}.
89
   */
90
  ConfigurationClassBeanDefinitionReader(BootstrapContext bootstrapContext,
91
          BeanNameGenerator importBeanNameGenerator, ImportRegistry importRegistry) {
2✔
92

93
    this.bootstrapContext = bootstrapContext;
3✔
94
    this.importRegistry = importRegistry;
3✔
95
    this.importBeanNameGenerator = importBeanNameGenerator;
3✔
96
  }
1✔
97

98
  /**
99
   * Read {@code configurationModel}, registering bean definitions
100
   * with the registry based on its contents.
101
   */
102
  public void loadBeanDefinitions(Set<ConfigurationClass> configurationModel) {
103
    TrackedConditionEvaluator trackedConditionEvaluator = new TrackedConditionEvaluator();
5✔
104
    for (ConfigurationClass configClass : configurationModel) {
10✔
105
      loadBeanDefinitionsForConfigurationClass(configClass, trackedConditionEvaluator);
4✔
106
    }
1✔
107
  }
1✔
108

109
  /**
110
   * Read a particular {@link ConfigurationClass}, registering bean definitions
111
   * for the class itself and all of its {@link Component} methods.
112
   */
113
  private void loadBeanDefinitionsForConfigurationClass(
114
          ConfigurationClass configClass, TrackedConditionEvaluator trackedConditionEvaluator) {
115

116
    if (trackedConditionEvaluator.shouldSkip(configClass)) {
4✔
117
      String beanName = configClass.beanName;
3✔
118
      // TODO annotated with both @Component and @ConditionalOnMissingBean,condition matching error
119
      if (StringUtils.isNotEmpty(beanName) && bootstrapContext.containsBeanDefinition(beanName)) {
8!
120
        bootstrapContext.removeBeanDefinition(beanName);
4✔
121
      }
122
      importRegistry.removeImportingClass(configClass.metadata.getClassName());
6✔
123
    }
1✔
124
    else {
125
      boolean disableAllDependencyInjection = isDisableAllDependencyInjection(configClass);
4✔
126
      if (configClass.isImported()) {
3✔
127
        registerBeanDefinitionForImportedConfigurationClass(configClass, disableAllDependencyInjection);
4✔
128
      }
129

130
      for (ComponentMethod componentMethod : configClass.componentMethods) {
11✔
131
        loadBeanDefinitionsForComponentMethod(componentMethod, disableAllDependencyInjection);
4✔
132
      }
1✔
133

134
      loadBeanDefinitionsFromImportedResources(configClass.importedResources);
4✔
135
      loadBeanDefinitionsFromImportBeanDefinitionRegistrars(configClass.importBeanDefinitionRegistrars);
4✔
136
      loadBeanDefinitionsFromBeanRegistrars(configClass.beanRegistrars);
4✔
137
    }
138
  }
1✔
139

140
  /**
141
   * Register the {@link Configuration} class itself as a bean definition.
142
   */
143
  private void registerBeanDefinitionForImportedConfigurationClass(ConfigurationClass configClass, boolean disableAllDependencyInjection) {
144
    var configBeanDef = new AnnotatedGenericBeanDefinition(configClass.metadata);
6✔
145

146
    ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(configBeanDef);
4✔
147
    configBeanDef.setScope(scopeMetadata.getScopeName());
4✔
148
    // import bean name
149
    String configBeanName = importBeanNameGenerator.generateBeanName(configBeanDef, bootstrapContext.getRegistry());
8✔
150
    AnnotationConfigUtils.applyAnnotationMetadata(configBeanDef, false);
3✔
151

152
    BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(configBeanDef, configBeanName);
6✔
153
    definitionHolder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, bootstrapContext.getRegistry());
7✔
154
    bootstrapContext.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
7✔
155
    configClass.setBeanName(configBeanName);
3✔
156

157
    boolean enableDependencyInjection = isEnableDependencyInjection(configClass.metadata.getAnnotations(), disableAllDependencyInjection);
7✔
158
    configBeanDef.setEnableDependencyInjection(enableDependencyInjection);
3✔
159

160
    if (logger.isTraceEnabled()) {
3!
161
      logger.trace("Registered bean definition for imported class '{}'", configBeanName);
×
162
    }
163
  }
1✔
164

165
  /**
166
   * Read the given {@link ComponentMethod}, registering bean definitions
167
   * with the BeanDefinitionRegistry based on its contents.
168
   */
169
  private void loadBeanDefinitionsForComponentMethod(ComponentMethod componentMethod, boolean disableAllDependencyInjection) {
170
    ConfigurationClass configClass = componentMethod.configurationClass;
3✔
171
    MethodMetadata metadata = componentMethod.metadata;
3✔
172
    String methodName = metadata.getMethodName();
3✔
173

174
    // Do we need to mark the bean as skipped by its condition?
175
    if (bootstrapContext.shouldSkip(metadata, ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN)) {
6✔
176
      configClass.skippedComponentMethods.add(methodName);
5✔
177
      return;
1✔
178
    }
179
    if (configClass.skippedComponentMethods.contains(methodName)) {
5!
180
      return;
×
181
    }
182
    MergedAnnotations annotations = metadata.getAnnotations();
3✔
183
    MergedAnnotation<Component> component = annotations.get(Component.class);
4✔
184
    Assert.state(component.isPresent(), "No @Component annotation attributes");
4✔
185

186
    // Consider name and any aliases.
187
    String[] explicitNames = component.getStringArray("name");
4✔
188
    String beanName = (explicitNames.length > 0 && StringUtils.hasText(explicitNames[0])) ? explicitNames[0] : null;
14!
189
    String localBeanName = defaultBeanName(beanName, methodName);
4✔
190
    beanName = this.importBeanNameGenerator instanceof ConfigurationBeanNameGenerator cbng ?
9✔
191
            cbng.deriveBeanName(metadata, beanName) : defaultBeanName(beanName, methodName);
9✔
192
    if (explicitNames.length > 0) {
3✔
193
      // Register aliases even when overridden below.
194
      for (int i = 1; i < explicitNames.length; i++) {
8✔
195
        bootstrapContext.registerAlias(beanName, explicitNames[i]);
7✔
196
      }
197
    }
198

199
    var beanDef = new ConfigurationClassBeanDefinition(configClass, metadata, localBeanName);
7✔
200
    beanDef.setSource(configClass.resource);
4✔
201
    beanDef.setResource(configClass.resource);
4✔
202

203
    // Has this effectively been overridden before (e.g. via XML)?
204
    if (isOverriddenByExistingDefinition(componentMethod, beanName, beanDef)) {
6✔
205
      if (beanName.equals(componentMethod.configurationClass.beanName)) {
6✔
206
        throw new BeanDefinitionStoreException(componentMethod.configurationClass.resource.toString(),
14✔
207
                beanName, ("Bean name derived from @Component method '%s' clashes with bean name for containing configuration class; " +
208
                "please make those names unique!").formatted(componentMethod.metadata.getMethodName()));
5✔
209
      }
210
      return;
1✔
211
    }
212

213
    boolean enableDI = isEnableDependencyInjection(annotations, disableAllDependencyInjection);
5✔
214
    beanDef.setEnableDependencyInjection(enableDI);
3✔
215

216
    AnnotationMetadata configClassMetadata = configClass.metadata;
3✔
217
    if (metadata.isStatic()) {
3✔
218
      // static @Component method
219
      if (configClassMetadata instanceof StandardAnnotationMetadata) {
3✔
220
        beanDef.setBeanClass(((StandardAnnotationMetadata) configClassMetadata).getIntrospectedClass());
6✔
221
      }
222
      else {
223
        beanDef.setBeanClassName(configClassMetadata.getClassName());
4✔
224
      }
225
      beanDef.setUniqueFactoryMethodName(methodName);
4✔
226
    }
227
    else {
228
      // instance @Component method
229
      beanDef.setFactoryBeanName(configClass.beanName);
4✔
230
      beanDef.setUniqueFactoryMethodName(methodName);
3✔
231
    }
232

233
    if (metadata instanceof StandardMethodMetadata smm && configClass.metadata instanceof StandardAnnotationMetadata sam) {
15!
234
      Method method = ReflectionUtils.getMostSpecificMethod(smm.getIntrospectedMethod(), sam.getIntrospectedClass());
6✔
235
      if (method == smm.getIntrospectedMethod()) {
4✔
236
        beanDef.setResolvedFactoryMethod(method);
3✔
237
      }
238
    }
239

240
    beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
3✔
241
    AnnotationConfigUtils.applyAnnotationMetadata(beanDef, false);
3✔
242

243
    if (!component.getBoolean("autowireCandidate")) {
4✔
244
      beanDef.setAutowireCandidate(false);
3✔
245
    }
246

247
    if (!component.getBoolean("defaultCandidate")) {
4✔
248
      beanDef.setDefaultCandidate(false);
3✔
249
    }
250

251
    var instantiation = component.getEnum("bootstrap", Component.Bootstrap.class);
6✔
252
    if (instantiation == Component.Bootstrap.BACKGROUND) {
3✔
253
      beanDef.setBackgroundInit(true);
3✔
254
    }
255

256
    String[] initMethodName = component.getStringArray("initMethods");
4✔
257
    if (ObjectUtils.isNotEmpty(initMethodName)) {
3✔
258
      beanDef.setInitMethodNames(initMethodName);
3✔
259
    }
260

261
    String destroyMethodName = component.getString("destroyMethod");
4✔
262
    beanDef.setDestroyMethodName(destroyMethodName);
3✔
263

264
    // Consider scoping
265
    ScopedProxyMode proxyMode = ScopedProxyMode.NO;
2✔
266
    MergedAnnotation<Scope> scope = annotations.get(Scope.class);
4✔
267
    if (scope.isPresent()) {
3✔
268
      beanDef.setScope(scope.getString("value"));
5✔
269
      proxyMode = scope.getEnum("proxyMode", ScopedProxyMode.class);
6✔
270
      if (proxyMode == ScopedProxyMode.DEFAULT) {
3✔
271
        proxyMode = ScopedProxyMode.NO;
2✔
272
      }
273
    }
274

275
    // Replace the original bean definition with the target one, if necessary
276
    BeanDefinition beanDefToRegister;
277
    if (proxyMode != ScopedProxyMode.NO) {
3✔
278
      BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(new BeanDefinitionHolder(beanDef, beanName),
9✔
279
              bootstrapContext.getRegistry(), proxyMode == ScopedProxyMode.TARGET_CLASS);
7✔
280
      beanDefToRegister = new ConfigurationClassBeanDefinition(
3✔
281
              (RootBeanDefinition) proxyDef.getBeanDefinition(), configClass, metadata, localBeanName);
7✔
282
    }
1✔
283
    else {
284
      beanDefToRegister = beanDef;
2✔
285
    }
286

287
    // Replace the original bean definition with the target one, if necessary
288
    if (logger.isTraceEnabled()) {
3!
289
      logger.trace("Registering bean definition for @Component method {}.{}()",
×
290
              configClassMetadata.getClassName(), beanName);
×
291
    }
292

293
    bootstrapContext.registerBeanDefinition(beanName, beanDefToRegister);
5✔
294
  }
1✔
295

296
  private static String defaultBeanName(@Nullable String beanName, String methodName) {
297
    return beanName != null ? beanName : methodName;
6✔
298
  }
299

300
  /**
301
   * disable all member class DI
302
   *
303
   * @param configClass current config class
304
   */
305
  private boolean isDisableAllDependencyInjection(ConfigurationClass configClass) {
306
    if (!configClass.metadata.isAnnotated(DisableAllDependencyInjection.class)) {
5✔
307
      try {
308
        String enclosingClassName = configClass.metadata.getEnclosingClassName();
4✔
309
        while (enclosingClassName != null) {
2✔
310
          AnnotationMetadata enclosingMetadata = bootstrapContext.getAnnotationMetadata(enclosingClassName);
5✔
311
          if (enclosingMetadata.isAnnotated(DisableAllDependencyInjection.class)) {
4✔
312
            return true;
2✔
313
          }
314
          enclosingClassName = enclosingMetadata.getEnclosingClassName();
3✔
315
        }
1✔
316
      }
317
      catch (Exception e) {
1✔
318
        logger.error("Failed to read class file via ASM for determining DI status order", e);
4✔
319
      }
1✔
320
      return false;
2✔
321
    }
322
    return true;
2✔
323
  }
324

325
  private boolean isEnableDependencyInjection(MergedAnnotations annotations, boolean disableAllDependencyInjection) {
326
    return annotations.isPresent(EnableDependencyInjection.class)
9✔
327
            || !(disableAllDependencyInjection || annotations.isPresent(DisableDependencyInjection.class));
5✔
328
  }
329

330
  @SuppressWarnings("NullAway")
331
  private boolean isOverriddenByExistingDefinition(ComponentMethod componentMethod, String beanName, ConfigurationClassBeanDefinition newBeanDef) {
332
    if (!bootstrapContext.containsBeanDefinition(beanName)) {
5✔
333
      return false;
2✔
334
    }
335
    BeanDefinition existingBeanDef = bootstrapContext.getBeanDefinition(beanName);
5✔
336
    ConfigurationClass configClass = componentMethod.configurationClass;
3✔
337

338
    // If the bean method is an overloaded case on the same configuration class,
339
    // preserve the existing bean definition and mark it as overloaded.
340
    if (existingBeanDef instanceof ConfigurationClassBeanDefinition ccbd) {
6✔
341
      if (!ccbd.getMetadata().getClassName().equals(configClass.metadata.getClassName())) {
8✔
342
        return false;
2✔
343
      }
344
      if (ccbd.getFactoryMethodMetadata().getMethodName().equals(componentMethod.metadata.getMethodName())) {
8✔
345
        ccbd.setNonUniqueFactoryMethodName(ccbd.getFactoryMethodMetadata().getMethodName());
5✔
346
        return true;
2✔
347
      }
348
      Map<String, Object> attributes = configClass.metadata.getAnnotationAttributes(Configuration.class);
5✔
349
      if ((attributes != null && (Boolean) attributes.get("enforceUniqueMethods"))
10!
350
              || !bootstrapContext.getRegistry().isBeanDefinitionOverridable(beanName)) {
4✔
351
        throw new BeanDefinitionOverrideException(beanName, newBeanDef, existingBeanDef,
10✔
352
                "@Bean method override with same bean name but different method name: " + existingBeanDef);
353
      }
354
      return true;
2✔
355
    }
356

357
    // A bean definition resulting from a component scan can be silently overridden
358
    // by an @Component method, even when general overriding is disabled
359
    // as long as the bean class is the same.
360
    if (existingBeanDef instanceof ScannedGenericBeanDefinition scannedBeanDef) {
6✔
361
      if (componentMethod.metadata.getReturnTypeName().equals(scannedBeanDef.getBeanClassName())) {
7!
362
        bootstrapContext.removeBeanDefinition(beanName);
4✔
363
      }
364
      return false;
2✔
365
    }
366

367
    // Has the existing bean definition bean marked as a framework-generated bean?
368
    // -> allow the current bean method to override it, since it is application-level
369
    if (existingBeanDef.getRole() > BeanDefinition.ROLE_APPLICATION) {
3✔
370
      return false;
2✔
371
    }
372

373
    // At this point, it's a top-level override (probably XML), just having been parsed
374
    // before configuration class processing kicks in...
375
    if (!bootstrapContext.getRegistry().isBeanDefinitionOverridable(beanName)) {
6✔
376
      throw new BeanDefinitionOverrideException(beanName, newBeanDef,
10✔
377
              existingBeanDef, "@Component definition illegally overridden by existing bean definition: " + existingBeanDef);
378
    }
379
    if (logger.isDebugEnabled()) {
3!
380
      logger.debug("Skipping bean definition for {}: a definition for bean '{}' " +
×
381
              "already exists. This top-level bean definition is considered as an override.", componentMethod, beanName);
382
    }
383
    return true;
2✔
384
  }
385

386
  private void loadBeanDefinitionsFromImportedResources(Map<String, Class<? extends BeanDefinitionReader>> importedResources) {
387
    HashMap<Class<?>, BeanDefinitionReader> readerInstanceCache = new HashMap<>();
4✔
388

389
    for (Map.Entry<String, Class<? extends BeanDefinitionReader>> entry : importedResources.entrySet()) {
11✔
390
      String resource = entry.getKey();
4✔
391
      Class<? extends BeanDefinitionReader> readerClass = entry.getValue();
4✔
392
      // Default reader selection necessary?
393
      if (BeanDefinitionReader.class == readerClass) {
3!
394
        // Primarily ".xml" files but for any other extension as well
395
        readerClass = XmlBeanDefinitionReader.class;
2✔
396
      }
397

398
      BeanDefinitionReader reader = readerInstanceCache.get(readerClass);
5✔
399
      if (reader == null) {
2✔
400
        try {
401
          // Instantiate the specified BeanDefinitionReader
402
          reader = readerClass.getConstructor(BeanDefinitionRegistry.class).newInstance(bootstrapContext.getRegistry());
19✔
403
          // Delegate the current ResourceLoader to it if possible
404
          if (reader instanceof AbstractBeanDefinitionReader abdr) {
6!
405
            abdr.setEnvironment(bootstrapContext.getEnvironment());
5✔
406
            abdr.setResourceLoader(bootstrapContext.getResourceLoader());
5✔
407
          }
408
          readerInstanceCache.put(readerClass, reader);
5✔
409
        }
410
        catch (Throwable ex) {
×
411
          throw new IllegalStateException("Could not instantiate BeanDefinitionReader class [%s]"
×
412
                  .formatted(readerClass.getName()), ex);
×
413
        }
1✔
414
      }
415

416
      reader.loadBeanDefinitions(resource);
4✔
417
    }
1✔
418

419
  }
1✔
420

421
  private void loadBeanDefinitionsFromImportBeanDefinitionRegistrars(Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> registrars) {
422
    for (var entry : registrars.entrySet()) {
11✔
423
      entry.getKey().registerBeanDefinitions(entry.getValue(), bootstrapContext, importBeanNameGenerator);
11✔
424
    }
1✔
425
  }
1✔
426

427
  private void loadBeanDefinitionsFromBeanRegistrars(Map<String, BeanRegistrar> registrars) {
428
    for (BeanRegistrar registrar : registrars.values()) {
11✔
429
      registrar.register(new BeanRegistryAdapter(bootstrapContext.getRegistry(),
9✔
430
              bootstrapContext.getBeanFactory(), bootstrapContext.getEnvironment(), registrar.getClass()), bootstrapContext.getEnvironment());
10✔
431
    }
1✔
432
  }
1✔
433

434
  /**
435
   * Evaluate {@code @Conditional} annotations, tracking results and taking into
436
   * account 'imported by'.
437
   */
438
  private final class TrackedConditionEvaluator {
5✔
439

440
    private final HashMap<ConfigurationClass, Boolean> skipped = new HashMap<>();
6✔
441

442
    public boolean shouldSkip(ConfigurationClass configClass) {
443
      Boolean skip = this.skipped.get(configClass);
6✔
444
      if (skip == null) {
2✔
445
        if (configClass.isImported()) {
3✔
446
          boolean allSkipped = true;
2✔
447
          for (ConfigurationClass importedBy : configClass.importedBy) {
11✔
448
            if (!shouldSkip(importedBy)) {
4✔
449
              allSkipped = false;
2✔
450
              break;
1✔
451
            }
452
          }
1✔
453
          if (allSkipped) {
2✔
454
            // The config classes that imported this one were all skipped, therefore we are skipped...
455
            skip = true;
3✔
456
          }
457
        }
458
        if (skip == null) {
2✔
459
          skip = bootstrapContext.shouldSkip(configClass.metadata, ConfigurationCondition.ConfigurationPhase.REGISTER_BEAN);
9✔
460
        }
461
        this.skipped.put(configClass, skip);
6✔
462
      }
463
      return skip;
3✔
464
    }
465
  }
466

467
  /**
468
   * {@link RootBeanDefinition} marker subclass used to signify that a bean definition
469
   * was created from a configuration class as opposed to any other configuration source.
470
   * Used in bean overriding cases where it's necessary to determine whether the bean
471
   * definition was created externally.
472
   */
473
  private static final class ConfigurationClassBeanDefinition extends RootBeanDefinition
474
          implements AnnotatedBeanDefinition {
475

476
    @Serial
477
    private static final long serialVersionUID = 1L;
478

479
    private final AnnotationMetadata annotationMetadata;
480

481
    private final MethodMetadata factoryMethodMetadata;
482

483
    private final String localBeanName;
484

485
    public ConfigurationClassBeanDefinition(ConfigurationClass configClass,
486
            MethodMetadata beanMethodMetadata, String localBeanName) {
2✔
487

488
      this.annotationMetadata = configClass.metadata;
4✔
489
      this.factoryMethodMetadata = beanMethodMetadata;
3✔
490
      this.localBeanName = localBeanName;
3✔
491
      setResource(configClass.resource);
4✔
492
      setLenientConstructorResolution(false);
3✔
493
    }
1✔
494

495
    public ConfigurationClassBeanDefinition(RootBeanDefinition original,
496
            ConfigurationClass configClass, MethodMetadata beanMethodMetadata, String localBeanName) {
497
      super(original);
3✔
498
      this.annotationMetadata = configClass.metadata;
4✔
499
      this.factoryMethodMetadata = beanMethodMetadata;
3✔
500
      this.localBeanName = localBeanName;
3✔
501
    }
1✔
502

503
    private ConfigurationClassBeanDefinition(ConfigurationClassBeanDefinition original) {
504
      super(original);
3✔
505
      this.annotationMetadata = original.annotationMetadata;
4✔
506
      this.factoryMethodMetadata = original.factoryMethodMetadata;
4✔
507
      this.localBeanName = original.localBeanName;
4✔
508
    }
1✔
509

510
    @Override
511
    public AnnotationMetadata getMetadata() {
512
      return this.annotationMetadata;
3✔
513
    }
514

515
    @Override
516
    public MethodMetadata getFactoryMethodMetadata() {
517
      return this.factoryMethodMetadata;
3✔
518
    }
519

520
    @Override
521
    public boolean isFactoryMethod(Method candidate) {
522
      return super.isFactoryMethod(candidate)
6✔
523
              && BeanAnnotationHelper.isBeanAnnotated(candidate)
3✔
524
              && BeanAnnotationHelper.determineBeanNameFor(candidate).equals(localBeanName);
8✔
525
    }
526

527
    @Override
528
    public ConfigurationClassBeanDefinition cloneBeanDefinition() {
529
      return new ConfigurationClassBeanDefinition(this);
5✔
530
    }
531
  }
532

533
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc