1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
31
32 public class Spr12334Tests {
33
34 @Test
35 public void shouldNotScanTwice() {
36 TestImport.scanned = false;
37
38 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
39 context.scan(TestImport.class.getPackage().getName());
40 context.refresh();
41 context.getBean(TestConfiguration.class);
42 }
43
44
45 @Import(TestImport.class)
46 public @interface AnotherImport {
47 }
48
49
50 @Configuration
51 @AnotherImport
52 public static class TestConfiguration {
53 }
54
55
56 public static class TestImport implements ImportBeanDefinitionRegistrar {
57
58 private static boolean scanned = false;
59
60 @Override
61 public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
62 if (scanned) {
63 throw new IllegalStateException("Already scanned");
64 }
65 scanned = true;
66 }
67 }
68
69 }