-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Document placeholder and Ant-style pattern support for @ComponentScan
#35491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,45 @@ sure that they are 'opened' (that is, that they use an `opens` declaration inste | |
`exports` declaration in your `module-info` descriptor). | ||
==== | ||
|
||
==== Property placeholders and Ant-style patterns | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future reference, please note that we do our best to introduce custom anchors that align with other anchors used in the same file. For example, I've added the following that I will apply after merging this PR. [[beans-scanning-placeholders-and-patterns]] |
||
|
||
`@ComponentScan(basePackages)` supports `${…}` property placeholders resolved | ||
against the `Environment` and Ant-style package patterns such as `com.example.**`. | ||
Multiple packages and/or patterns may be specified. | ||
|
||
[tabs] | ||
====== | ||
Java:: | ||
+ | ||
[source,java,indent=0,subs="verbatim,quotes"] | ||
---- | ||
@Configuration | ||
@ComponentScan(basePackages = "${app.scan.packages}") | ||
public class AppConfig { | ||
// ... | ||
} | ||
---- | ||
|
||
Kotlin:: | ||
+ | ||
[source,kotlin,indent=0,subs="verbatim,quotes"] | ||
---- | ||
@Configuration | ||
@ComponentScan(basePackages = ["\${app.scan.packages}"]) | ||
class AppConfig { | ||
// ... | ||
} | ||
---- | ||
====== | ||
|
||
[source,properties,indent=0,subs="verbatim,quotes"] | ||
---- | ||
app.scan.packages=com.example.**,org.acme.* | ||
---- | ||
|
||
NOTE: Ant-style patterns do not apply to `basePackageClasses`, which accepts concrete | ||
classes and derives packages from those classes. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: the following paragraph and note belong to the previous section about XML configuration. However, I have addressed this locally, thus there is no need to update this PR. |
||
Furthermore, the `AutowiredAnnotationBeanPostProcessor` and | ||
`CommonAnnotationBeanPostProcessor` are both implicitly included when you use the | ||
component-scan element. That means that the two components are autodetected and | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,10 @@ | |
* <p>Allows for more concise annotation declarations if no other attributes | ||
* are needed — for example, {@code @ComponentScan("org.my.pkg")} | ||
* instead of {@code @ComponentScan(basePackages = "org.my.pkg")}. | ||
* <p>This attribute has the same semantics as {@link #basePackages}, including | ||
* support for {@code ${...}} placeholders (resolved against the | ||
* {@link org.springframework.core.env.Environment Environment}) and | ||
* Ant-style package patterns (for example, {@code com.example.**}). | ||
*/ | ||
@AliasFor("basePackages") | ||
String[] value() default {}; | ||
|
@@ -86,6 +90,13 @@ | |
* attribute. | ||
* <p>Use {@link #basePackageClasses} for a type-safe alternative to | ||
* String-based package names. | ||
* <p>Supports {@code ${...}} placeholders resolved against the | ||
* {@link org.springframework.core.env.Environment Environment} as well as | ||
* Ant-style package patterns (for example, {@code com.example.**}). | ||
* Multiple packages and/or patterns may be specified. | ||
* <p><strong>Note:</strong> Ant-style patterns are <em>not</em> applicable to | ||
* {@link #basePackageClasses()}, which accepts concrete classes for type-safe | ||
* package selection. | ||
Comment on lines
+97
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there is any need to point this out, since one can only supply Thus, I have removed this and other such text locally. |
||
*/ | ||
@AliasFor("value") | ||
String[] basePackages() default {}; | ||
|
@@ -95,6 +106,8 @@ | |
* to scan for annotated components. The package of each class specified will be scanned. | ||
* <p>Consider creating a special no-op marker class or interface in each package | ||
* that serves no purpose other than being referenced by this attribute. | ||
* <p><strong>Note:</strong> Ant-style package patterns do not apply here; this | ||
* attribute accepts concrete classes only and derives packages from those classes. | ||
*/ | ||
Class<?>[] basePackageClasses() default {}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note that this breaks the build.
However, I have addressed this locally, thus there is no need to update this PR.