|
| 1 | +/* |
| 2 | + * Copyright 2002-2011 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; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | +import org.springframework.context.annotation.componentscan.simple.SimpleComponent; |
| 21 | + |
| 22 | +/** |
| 23 | + * Tests covering overlapping use of @ComponentScan and @Import annotations. |
| 24 | + * |
| 25 | + * @author Chris Beams |
| 26 | + * @since 3.1 |
| 27 | + */ |
| 28 | +public class ComponentScanAndImportAnnotationInteractionTests { |
| 29 | + |
| 30 | + @Test |
| 31 | + public void componentScanOverlapsWithImport() { |
| 32 | + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
| 33 | + ctx.register(Config1.class); |
| 34 | + ctx.register(Config2.class); |
| 35 | + ctx.refresh(); // no conflicts found trying to register SimpleComponent |
| 36 | + ctx.getBean(SimpleComponent.class); // succeeds -> there is only one bean of type SimpleComponent |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + @Configuration |
| 41 | + @ComponentScan("org.springframework.context.annotation.componentscan.simple") |
| 42 | + static class Config1 { |
| 43 | + |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + @Configuration |
| 48 | + @Import(org.springframework.context.annotation.componentscan.simple.SimpleComponent.class) |
| 49 | + static class Config2 { |
| 50 | + |
| 51 | + } |
| 52 | +} |
0 commit comments