Introduced AnnotationConfigRegistry as common interface for AnnotationConfig(Web)ApplicationContext

Issue: SPR-11814
master
Juergen Hoeller 10 years ago
parent 591f79514d
commit b3e3c5312f
  1. 16
      spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java
  2. 43
      spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigRegistry.java
  3. 16
      spring-web/src/main/java/org/springframework/web/context/support/AnnotationConfigWebApplicationContext.java

@ -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();

@ -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);
}

@ -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.
@ -23,6 +23,7 @@ import java.util.Set;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigRegistry;
import org.springframework.context.annotation.AnnotationConfigUtils;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.ScopeMetadataResolver;
@ -78,7 +79,8 @@ import org.springframework.web.context.ContextLoader;
* @since 3.0
* @see org.springframework.context.annotation.AnnotationConfigApplicationContext
*/
public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWebApplicationContext {
public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWebApplicationContext
implements AnnotationConfigRegistry {
private BeanNameGenerator beanNameGenerator;
@ -130,10 +132,8 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
/**
* 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 org.springframework.context.annotation.Configuration @Configuration} classes
* @see #scan(String...)
@ -148,8 +148,8 @@ public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWe
/**
* 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 #loadBeanDefinitions(DefaultListableBeanFactory)
* @see #register(Class...)

Loading…
Cancel
Save