Skip to content

Commit 0e90776

Browse files
committed
Test for ImportBeanDefinitionRegistrar double scan
Issue: SPR-12334 (cherry picked from commit 38030ef)
1 parent a305bf7 commit 0e90776

File tree

1 file changed

+67
-0
lines changed
  • spring-context/src/test/java/org/springframework/context/annotation/spr12334

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2002-2014 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+
* http://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.spr12334;
18+
19+
import org.junit.Test;
20+
21+
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
22+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
23+
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.context.annotation.Import;
25+
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
26+
import org.springframework.core.type.AnnotationMetadata;
27+
28+
/**
29+
* @author Juergen Hoeller
30+
* @author Alex Pogrebnyak
31+
*/
32+
public class Spr12334Tests {
33+
34+
@Test
35+
public void shouldNotScanTwice() {
36+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
37+
context.scan(TestImport.class.getPackage().getName());
38+
context.refresh();
39+
context.getBean(TestConfiguration.class);
40+
}
41+
42+
43+
@Import(TestImport.class)
44+
public @interface AnotherImport {
45+
}
46+
47+
48+
@Configuration
49+
@AnotherImport
50+
public static class TestConfiguration {
51+
}
52+
53+
54+
public static class TestImport implements ImportBeanDefinitionRegistrar {
55+
56+
private boolean scanned = false;
57+
58+
@Override
59+
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
60+
if (this.scanned) {
61+
throw new IllegalStateException("Already scanned");
62+
}
63+
this.scanned = true;
64+
}
65+
}
66+
67+
}

0 commit comments

Comments
 (0)