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

TAKETODAY / today-infrastructure / 16489896461

24 Jul 2025 06:51AM UTC coverage: 81.782%. Remained the same
16489896461

push

github

TAKETODAY
:sparkles: LogMessage API

59446 of 77637 branches covered (76.57%)

Branch coverage included in aggregate %.

140767 of 167176 relevant lines covered (84.2%)

3.6 hits per line

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

94.32
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 java.io.Serial;
21
import java.lang.reflect.Method;
22
import java.util.ArrayList;
23
import java.util.HashMap;
24
import java.util.Map;
25
import java.util.Set;
26

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

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

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

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

81
  private final ImportRegistry importRegistry;
82

83
  private final BootstrapContext bootstrapContext;
84

85
  private final BeanNameGenerator importBeanNameGenerator;
86

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

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

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

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

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

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

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

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

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

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

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

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

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

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

187
    // Consider name and any aliases
188
    ArrayList<String> names = CollectionUtils.newArrayList(component.getStringArray("name"));
5✔
189

190
    // Consider name and any aliases.
191
    String[] explicitNames = component.getStringArray("name");
4✔
192
    String beanName;
193
    String localBeanName;
194
    if (explicitNames.length > 0 && StringUtils.hasText(explicitNames[0])) {
8!
195
      beanName = explicitNames[0];
4✔
196
      localBeanName = beanName;
2✔
197
      // Register aliases even when overridden below.
198
      for (int i = 1; i < explicitNames.length; i++) {
9✔
199
        bootstrapContext.registerAlias(beanName, explicitNames[i]);
7✔
200
      }
201
    }
202
    else {
203
      // Default bean name derived from method name.
204
      beanName = this.importBeanNameGenerator instanceof ConfigurationBeanNameGenerator cbng
9✔
205
              ? cbng.deriveBeanName(metadata) : methodName;
6✔
206
      localBeanName = methodName;
2✔
207
    }
208

209
    var beanDef = new ConfigurationClassBeanDefinition(configClass, metadata, localBeanName);
7✔
210
    beanDef.setSource(configClass.resource);
4✔
211
    beanDef.setResource(configClass.resource);
4✔
212

213
    // Has this effectively been overridden before (e.g. via XML)?
214
    if (isOverriddenByExistingDefinition(componentMethod, beanName, beanDef)) {
6✔
215
      if (beanName.equals(componentMethod.configurationClass.beanName)) {
6✔
216
        throw new BeanDefinitionStoreException(componentMethod.configurationClass.resource.toString(),
14✔
217
                beanName, ("Bean name derived from @Component method '%s' clashes with bean name for containing configuration class; " +
218
                "please make those names unique!").formatted(componentMethod.metadata.getMethodName()));
5✔
219
      }
220
      return;
1✔
221
    }
222

223
    boolean enableDI = isEnableDependencyInjection(annotations, disableAllDependencyInjection);
5✔
224
    beanDef.setEnableDependencyInjection(enableDI);
3✔
225

226
    AnnotationMetadata configClassMetadata = configClass.metadata;
3✔
227
    if (metadata.isStatic()) {
3✔
228
      // static @Component method
229
      if (configClassMetadata instanceof StandardAnnotationMetadata) {
3✔
230
        beanDef.setBeanClass(((StandardAnnotationMetadata) configClassMetadata).getIntrospectedClass());
6✔
231
      }
232
      else {
233
        beanDef.setBeanClassName(configClassMetadata.getClassName());
4✔
234
      }
235
      beanDef.setUniqueFactoryMethodName(methodName);
4✔
236
    }
237
    else {
238
      // instance @Component method
239
      beanDef.setFactoryBeanName(configClass.beanName);
4✔
240
      beanDef.setUniqueFactoryMethodName(methodName);
3✔
241
    }
242

243
    if (metadata instanceof StandardMethodMetadata smm && configClass.metadata instanceof StandardAnnotationMetadata sam) {
15!
244
      Method method = ReflectionUtils.getMostSpecificMethod(smm.getIntrospectedMethod(), sam.getIntrospectedClass());
6✔
245
      if (method == smm.getIntrospectedMethod()) {
4✔
246
        beanDef.setResolvedFactoryMethod(method);
3✔
247
      }
248
    }
249

250
    beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
3✔
251
    AnnotationConfigUtils.applyAnnotationMetadata(beanDef, false);
3✔
252

253
    if (!component.getBoolean("autowireCandidate")) {
4✔
254
      beanDef.setAutowireCandidate(false);
3✔
255
    }
256

257
    if (!component.getBoolean("defaultCandidate")) {
4✔
258
      beanDef.setDefaultCandidate(false);
3✔
259
    }
260

261
    var instantiation = component.getEnum("bootstrap", Component.Bootstrap.class);
6✔
262
    if (instantiation == Component.Bootstrap.BACKGROUND) {
3✔
263
      beanDef.setBackgroundInit(true);
3✔
264
    }
265

266
    String[] initMethodName = component.getStringArray("initMethods");
4✔
267
    if (ObjectUtils.isNotEmpty(initMethodName)) {
3✔
268
      beanDef.setInitMethodNames(initMethodName);
3✔
269
    }
270

271
    String destroyMethodName = component.getString("destroyMethod");
4✔
272
    beanDef.setDestroyMethodName(destroyMethodName);
3✔
273

274
    // Consider scoping
275
    ScopedProxyMode proxyMode = ScopedProxyMode.NO;
2✔
276
    MergedAnnotation<Scope> scope = annotations.get(Scope.class);
4✔
277
    if (scope.isPresent()) {
3✔
278
      beanDef.setScope(scope.getString("value"));
5✔
279
      proxyMode = scope.getEnum("proxyMode", ScopedProxyMode.class);
6✔
280
      if (proxyMode == ScopedProxyMode.DEFAULT) {
3✔
281
        proxyMode = ScopedProxyMode.NO;
2✔
282
      }
283
    }
284

285
    // Replace the original bean definition with the target one, if necessary
286
    BeanDefinition beanDefToRegister;
287
    if (proxyMode != ScopedProxyMode.NO) {
3✔
288
      BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(new BeanDefinitionHolder(beanDef, beanName),
9✔
289
              bootstrapContext.getRegistry(), proxyMode == ScopedProxyMode.TARGET_CLASS);
7✔
290
      beanDefToRegister = new ConfigurationClassBeanDefinition(
3✔
291
              (RootBeanDefinition) proxyDef.getBeanDefinition(), configClass, metadata, localBeanName);
7✔
292
    }
1✔
293
    else {
294
      beanDefToRegister = beanDef;
2✔
295
    }
296

297
    // Replace the original bean definition with the target one, if necessary
298
    if (logger.isTraceEnabled()) {
3!
299
      logger.trace("Registering bean definition for @Component method {}.{}()",
×
300
              configClassMetadata.getClassName(), beanName);
×
301
    }
302

303
    bootstrapContext.registerBeanDefinition(beanName, beanDefToRegister);
5✔
304
  }
1✔
305

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

331
  private boolean isEnableDependencyInjection(MergedAnnotations annotations, boolean disableAllDependencyInjection) {
332
    return annotations.isPresent(EnableDependencyInjection.class)
9✔
333
            || !(disableAllDependencyInjection || annotations.isPresent(DisableDependencyInjection.class));
5✔
334
  }
335

336
  private boolean isOverriddenByExistingDefinition(ComponentMethod componentMethod, String beanName, ConfigurationClassBeanDefinition newBeanDef) {
337
    if (!bootstrapContext.containsBeanDefinition(beanName)) {
5✔
338
      return false;
2✔
339
    }
340
    BeanDefinition existingBeanDef = bootstrapContext.getBeanDefinition(beanName);
5✔
341
    ConfigurationClass configClass = componentMethod.configurationClass;
3✔
342

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

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

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

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

391
  private void loadBeanDefinitionsFromImportedResources(Map<String, Class<? extends BeanDefinitionReader>> importedResources) {
392
    HashMap<Class<?>, BeanDefinitionReader> readerInstanceCache = new HashMap<>();
4✔
393

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

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

421
      reader.loadBeanDefinitions(resource);
4✔
422
    }
1✔
423

424
  }
1✔
425

426
  private void loadBeanDefinitionsFromImportBeanDefinitionRegistrars(Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> registrars) {
427
    for (var entry : registrars.entrySet()) {
11✔
428
      entry.getKey().registerBeanDefinitions(entry.getValue(), bootstrapContext, importBeanNameGenerator);
11✔
429
    }
1✔
430
  }
1✔
431

432
  private void loadBeanDefinitionsFromBeanRegistrars(Map<String, BeanRegistrar> registrars) {
433
    for (BeanRegistrar registrar : registrars.values()) {
11✔
434
      registrar.register(new BeanRegistryAdapter(bootstrapContext.getRegistry(),
9✔
435
              bootstrapContext.getBeanFactory(), bootstrapContext.getEnvironment(), registrar.getClass()), bootstrapContext.getEnvironment());
10✔
436
    }
1✔
437
  }
1✔
438

439
  /**
440
   * Evaluate {@code @Conditional} annotations, tracking results and taking into
441
   * account 'imported by'.
442
   */
443
  private final class TrackedConditionEvaluator {
5✔
444

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

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

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

481
    @Serial
482
    private static final long serialVersionUID = 1L;
483

484
    private final AnnotationMetadata annotationMetadata;
485

486
    private final MethodMetadata factoryMethodMetadata;
487

488
    private final String localBeanName;
489

490
    public ConfigurationClassBeanDefinition(ConfigurationClass configClass,
491
            MethodMetadata beanMethodMetadata, String localBeanName) {
2✔
492

493
      this.annotationMetadata = configClass.metadata;
4✔
494
      this.factoryMethodMetadata = beanMethodMetadata;
3✔
495
      this.localBeanName = localBeanName;
3✔
496
      setResource(configClass.resource);
4✔
497
      setLenientConstructorResolution(false);
3✔
498
    }
1✔
499

500
    public ConfigurationClassBeanDefinition(RootBeanDefinition original,
501
            ConfigurationClass configClass, MethodMetadata beanMethodMetadata, String localBeanName) {
502
      super(original);
3✔
503
      this.annotationMetadata = configClass.metadata;
4✔
504
      this.factoryMethodMetadata = beanMethodMetadata;
3✔
505
      this.localBeanName = localBeanName;
3✔
506
    }
1✔
507

508
    private ConfigurationClassBeanDefinition(ConfigurationClassBeanDefinition original) {
509
      super(original);
3✔
510
      this.annotationMetadata = original.annotationMetadata;
4✔
511
      this.factoryMethodMetadata = original.factoryMethodMetadata;
4✔
512
      this.localBeanName = original.localBeanName;
4✔
513
    }
1✔
514

515
    @Override
516
    public AnnotationMetadata getMetadata() {
517
      return this.annotationMetadata;
3✔
518
    }
519

520
    @Override
521
    @NonNull
522
    public MethodMetadata getFactoryMethodMetadata() {
523
      return this.factoryMethodMetadata;
3✔
524
    }
525

526
    @Override
527
    public boolean isFactoryMethod(Method candidate) {
528
      return super.isFactoryMethod(candidate)
6✔
529
              && BeanAnnotationHelper.isBeanAnnotated(candidate)
3✔
530
              && BeanAnnotationHelper.determineBeanNameFor(candidate).equals(localBeanName);
8✔
531
    }
532

533
    @Override
534
    public ConfigurationClassBeanDefinition cloneBeanDefinition() {
535
      return new ConfigurationClassBeanDefinition(this);
5✔
536
    }
537
  }
538

539
}
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