Skip to content

Commit b7a996a

Browse files
committed
Clarify component scanning of abstract classes with @⁠Lookup methods
Due to changes in gh-19118, classes that contain @⁠Lookup methods are no longer required to be concrete classes for use with component scanning; however, the reference documentation still states that such classes must not be abstract. This commit therefore removes the outdated reference documentation and updates the corresponding Javadoc. See gh-19118 Closes gh-34367 (cherry picked from commit 819a7c8)
1 parent 5b1a7c7 commit b7a996a

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

Diff for: framework-docs/modules/ROOT/pages/core/beans/dependencies/factory-method-injection.adoc

-7
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ dynamically generate a subclass that overrides the method.
120120
subclasses cannot be `final`, and the method to be overridden cannot be `final`, either.
121121
* Unit-testing a class that has an `abstract` method requires you to subclass the class
122122
yourself and to supply a stub implementation of the `abstract` method.
123-
* Concrete methods are also necessary for component scanning, which requires concrete
124-
classes to pick up.
125123
* A further key limitation is that lookup methods do not work with factory methods and
126124
in particular not with `@Bean` methods in configuration classes, since, in that case,
127125
the container is not in charge of creating the instance and therefore cannot create
@@ -293,11 +291,6 @@ Kotlin::
293291
----
294292
======
295293

296-
Note that you should typically declare such annotated lookup methods with a concrete
297-
stub implementation, in order for them to be compatible with Spring's component
298-
scanning rules where abstract classes get ignored by default. This limitation does not
299-
apply to explicitly registered or explicitly imported bean classes.
300-
301294
[TIP]
302295
====
303296
Another way of accessing differently scoped target beans is an `ObjectFactory`/

Diff for: spring-context/src/main/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProvider.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -565,9 +565,10 @@ private boolean isConditionMatch(MetadataReader metadataReader) {
565565
}
566566

567567
/**
568-
* Determine whether the given bean definition qualifies as candidate.
569-
* <p>The default implementation checks whether the class is not an interface
570-
* and not dependent on an enclosing class.
568+
* Determine whether the given bean definition qualifies as a candidate component.
569+
* <p>The default implementation checks whether the class is not dependent on an
570+
* enclosing class as well as whether the class is either concrete (and therefore
571+
* not an interface) or has {@link Lookup @Lookup} methods.
571572
* <p>Can be overridden in subclasses.
572573
* @param beanDefinition the bean definition to check
573574
* @return whether the bean definition qualifies as a candidate component

0 commit comments

Comments
 (0)