Introduced AnnotationConfigRegistry as common interface for AnnotationConfig(Web)ApplicationContext

Issue: SPR-11814
This commit is contained in:
Juergen Hoeller
2014-06-26 11:43:03 +02:00
parent 591f79514d
commit b3e3c5312f
3 changed files with 59 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@ import org.springframework.util.Assert;
* @see ClassPathBeanDefinitionScanner
* @see org.springframework.context.support.GenericXmlApplicationContext
*/
public class AnnotationConfigApplicationContext extends GenericApplicationContext {
public class AnnotationConfigApplicationContext extends GenericApplicationContext implements AnnotationConfigRegistry {
private final AnnotatedBeanDefinitionReader reader;
@@ -135,12 +135,11 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
this.scanner.setScopeMetadataResolver(scopeMetadataResolver);
}
/**
* Register one or more annotated classes to be processed.
* Note that {@link #refresh()} must be called in order for the context
* to fully process the new class.
* <p>Calls to {@code register} are idempotent; adding the same
* annotated class more than once has no additional effect.
* <p>Note that {@link #refresh()} must be called in order for the context
* to fully process the new classes.
* @param annotatedClasses one or more annotated classes,
* e.g. {@link Configuration @Configuration} classes
* @see #scan(String...)
@@ -153,8 +152,8 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
/**
* Perform a scan within the specified base packages.
* Note that {@link #refresh()} must be called in order for the context to
* fully process the new class.
* <p>Note that {@link #refresh()} must be called in order for the context
* to fully process the new classes.
* @param basePackages the packages to check for annotated classes
* @see #register(Class...)
* @see #refresh()
@@ -164,6 +163,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
this.scanner.scan(basePackages);
}
@Override
protected void prepareRefresh() {
this.scanner.clearCache();

View File

@@ -0,0 +1,43 @@
/*
* Copyright 2002-2014 the original author or authors.
*
* 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;
/**
* Common interface for annotation config application contexts,
* defining {@link #register} and {@link #scan} methods.
*
* @author Juergen Hoeller
* @since 4.1
*/
public interface AnnotationConfigRegistry {
/**
* Register one or more annotated classes to be processed.
* <p>Calls to {@code register} are idempotent; adding the same
* annotated class more than once has no additional effect.
* @param annotatedClasses one or more annotated classes,
* e.g. {@link Configuration @Configuration} classes
*/
void register(Class<?>... annotatedClasses);
/**
* Perform a scan within the specified base packages.
* @param basePackages the packages to check for annotated classes
*/
void scan(String... basePackages);
}