Skip to content

Commit 6699833

Browse files
committed
Introduce regression test for gh-24375
1 parent 095acef commit 6699833

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

Diff for: spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -42,6 +42,7 @@
4242

4343
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
4444
import org.springframework.beans.factory.config.BeanDefinition;
45+
import org.springframework.context.annotation.componentscan.gh24375.MyComponent;
4546
import org.springframework.context.index.CandidateComponentsTestClassLoader;
4647
import org.springframework.core.env.ConfigurableEnvironment;
4748
import org.springframework.core.env.StandardEnvironment;
@@ -501,6 +502,15 @@ public void testIntegrationWithAnnotationConfigApplicationContext_metaProfile()
501502
}
502503
}
503504

505+
@Test
506+
public void gh24375() {
507+
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
508+
Set<BeanDefinition> components = provider.findCandidateComponents(MyComponent.class.getPackage().getName());
509+
assertEquals(1, components.size());
510+
assertEquals(MyComponent.class.getName(), components.iterator().next().getBeanClassName());
511+
}
512+
513+
504514
private boolean containsBeanClass(Set<BeanDefinition> candidates, Class<?> beanClass) {
505515
for (BeanDefinition candidate : candidates) {
506516
if (beanClass.getName().equals(candidate.getBeanClassName())) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.annotation.componentscan.gh24375;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
import org.springframework.core.annotation.AliasFor;
25+
26+
@Target(ElementType.TYPE)
27+
@Retention(RetentionPolicy.RUNTIME)
28+
public @interface A {
29+
30+
@AliasFor("value")
31+
B other() default @B;
32+
33+
@AliasFor("other")
34+
B value() default @B;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.annotation.componentscan.gh24375;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
@Target(ElementType.ANNOTATION_TYPE)
25+
@Retention(RetentionPolicy.RUNTIME)
26+
public @interface B {
27+
28+
String name() default "";
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2002-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.context.annotation.componentscan.gh24375;
18+
19+
import org.springframework.stereotype.Component;
20+
21+
@Component
22+
@A(other = @B)
23+
public class MyComponent {
24+
}

0 commit comments

Comments
 (0)