ComponentScanAnnotationTests.java 1.8 KB
Newer Older
1
/*
2
 * Copyright 2002-2014 the original author or authors.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.context.annotation;

import org.junit.Test;
20

21
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
22
import org.springframework.context.annotation.ComponentScan.Filter;
23 24 25
import org.springframework.core.type.filter.TypeFilter;

/**
C
Chris Beams 已提交
26
 * Unit tests for the @ComponentScan annotation.
27 28 29
 *
 * @author Chris Beams
 * @since 3.1
30
 * @see ComponentScanAnnotationIntegrationTests
31 32
 */
public class ComponentScanAnnotationTests {
33

34
	@Test
35 36 37
	public void noop() {
		// no-op; the @ComponentScan-annotated MyConfig class below simply excercises
		// available attributes of the annotation.
38 39 40
	}
}

41 42 43

@interface MyAnnotation {
}
44 45 46

@Configuration
@ComponentScan(
47
	basePackageClasses={TestBean.class},
48 49 50 51
	nameGenerator = DefaultBeanNameGenerator.class,
	scopedProxy = ScopedProxyMode.NO,
	scopeResolver = AnnotationScopeMetadataResolver.class,
	resourcePattern = "**/*custom.class",
52
	useDefaultFilters = false,
53
	includeFilters = {
54
		@Filter(type = FilterType.ANNOTATION, value = MyAnnotation.class)
55 56
	},
	excludeFilters = {
57
		@Filter(type = FilterType.CUSTOM, value = TypeFilter.class)
58 59
	},
	lazyInit = true
60 61 62 63
)
class MyConfig {
}

64
@ComponentScan(basePackageClasses=example.scannable.NamedComponent.class)
65 66
class SimpleConfig {
}