Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 693f6dd

Browse filesBrowse files
committed
Filter source @configuration with @componentscan
Exclude self @component when parsing @componentscan annotations.
1 parent b578ab0 commit 693f6dd
Copy full SHA for 693f6dd

File tree

Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+9
-2
lines changed
Open diff view settings
Collapse file

‎spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java‎

Copy file name to clipboardExpand all lines: spring-context/src/main/java/org/springframework/context/annotation/ComponentScanAnnotationParser.java
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -28,6 +28,7 @@
2828
import org.springframework.core.annotation.AnnotationAttributes;
2929
import org.springframework.core.env.Environment;
3030
import org.springframework.core.io.ResourceLoader;
31+
import org.springframework.core.type.filter.AbstractTypeHierarchyTraversingFilter;
3132
import org.springframework.core.type.filter.AnnotationTypeFilter;
3233
import org.springframework.core.type.filter.AssignableTypeFilter;
3334
import org.springframework.core.type.filter.TypeFilter;
@@ -64,7 +65,7 @@ public ComponentScanAnnotationParser(ResourceLoader resourceLoader, Environment
6465
}
6566

6667

67-
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, String declaringClass) {
68+
public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, final String declaringClass) {
6869
ClassPathBeanDefinitionScanner scanner =
6970
new ClassPathBeanDefinitionScanner(this.registry, componentScan.getBoolean("useDefaultFilters"));
7071

@@ -120,6 +121,12 @@ public Set<BeanDefinitionHolder> parse(AnnotationAttributes componentScan, Strin
120121
basePackages.add(ClassUtils.getPackageName(declaringClass));
121122
}
122123

124+
scanner.addExcludeFilter(new AbstractTypeHierarchyTraversingFilter(false, false) {
125+
@Override
126+
protected boolean matchClassName(String className) {
127+
return declaringClass.equals(className);
128+
}
129+
});
123130
return scanner.doScan(StringUtils.toStringArray(basePackages));
124131
}
125132

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.