Skip to content

Commit 6e5b873

Browse files
committed
Polishing
(cherry picked from commit 8662c61)
1 parent 5fb4103 commit 6e5b873

File tree

7 files changed

+86
-41
lines changed

7 files changed

+86
-41
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionReaderUtils.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,6 +69,23 @@ public static AbstractBeanDefinition createBeanDefinition(
6969
return bd;
7070
}
7171

72+
/**
73+
* Generate a bean name for the given top-level bean definition,
74+
* unique within the given bean factory.
75+
* @param beanDefinition the bean definition to generate a bean name for
76+
* @param registry the bean factory that the definition is going to be
77+
* registered with (to check for existing bean names)
78+
* @return the generated bean name
79+
* @throws BeanDefinitionStoreException if no unique name can be generated
80+
* for the given bean definition
81+
* @see #generateBeanName(BeanDefinition, BeanDefinitionRegistry, boolean)
82+
*/
83+
public static String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry registry)
84+
throws BeanDefinitionStoreException {
85+
86+
return generateBeanName(beanDefinition, registry, false);
87+
}
88+
7289
/**
7390
* Generate a bean name for the given bean definition, unique within the
7491
* given bean factory.
@@ -117,22 +134,6 @@ else if (definition.getFactoryBeanName() != null) {
117134
return id;
118135
}
119136

120-
/**
121-
* Generate a bean name for the given top-level bean definition,
122-
* unique within the given bean factory.
123-
* @param beanDefinition the bean definition to generate a bean name for
124-
* @param registry the bean factory that the definition is going to be
125-
* registered with (to check for existing bean names)
126-
* @return the generated bean name
127-
* @throws BeanDefinitionStoreException if no unique name can be generated
128-
* for the given bean definition
129-
*/
130-
public static String generateBeanName(BeanDefinition beanDefinition, BeanDefinitionRegistry registry)
131-
throws BeanDefinitionStoreException {
132-
133-
return generateBeanName(beanDefinition, registry, false);
134-
}
135-
136137
/**
137138
* Register the given bean definition with the given bean factory.
138139
* @param definitionHolder the bean definition including name and aliases

spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java

+6
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,22 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
5353
* Name of the ConversionService bean in the factory.
5454
* If none is supplied, default conversion rules apply.
5555
* @see org.springframework.core.convert.ConversionService
56+
* @since 3.0
5657
*/
5758
String CONVERSION_SERVICE_BEAN_NAME = "conversionService";
5859

5960
/**
6061
* Name of the LoadTimeWeaver bean in the factory. If such a bean is supplied,
6162
* the context will use a temporary ClassLoader for type matching, in order
6263
* to allow the LoadTimeWeaver to process all actual bean classes.
64+
* @since 2.5
6365
* @see org.springframework.instrument.classloading.LoadTimeWeaver
6466
*/
6567
String LOAD_TIME_WEAVER_BEAN_NAME = "loadTimeWeaver";
6668

6769
/**
6870
* Name of the {@link Environment} bean in the factory.
71+
* @since 3.1
6972
*/
7073
String ENVIRONMENT_BEAN_NAME = "environment";
7174

@@ -84,6 +87,7 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
8487

8588
/**
8689
* Set the unique id of this application context.
90+
* @since 3.0
8791
*/
8892
void setId(String id);
8993

@@ -99,13 +103,15 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
99103

100104
/**
101105
* Return the Environment for this application context in configurable form.
106+
* @since 3.1
102107
*/
103108
@Override
104109
ConfigurableEnvironment getEnvironment();
105110

106111
/**
107112
* Set the {@code Environment} for this application context.
108113
* @param environment the new environment
114+
* @since 3.1
109115
*/
110116
void setEnvironment(ConfigurableEnvironment environment);
111117

spring-context/src/main/java/org/springframework/context/annotation/AnnotatedBeanDefinitionReader.java

+30
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environmen
8383
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
8484
}
8585

86+
8687
/**
8788
* Return the BeanDefinitionRegistry that this scanner operates on.
8889
*/
@@ -117,21 +118,50 @@ public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver
117118
(scopeMetadataResolver != null ? scopeMetadataResolver : new AnnotationScopeMetadataResolver());
118119
}
119120

121+
122+
/**
123+
* Register one or more annotated classes to be processed.
124+
* <p>Calls to {@code register} are idempotent; adding the same
125+
* annotated class more than once has no additional effect.
126+
* @param annotatedClasses one or more annotated classes,
127+
* e.g. {@link Configuration @Configuration} classes
128+
*/
120129
public void register(Class<?>... annotatedClasses) {
121130
for (Class<?> annotatedClass : annotatedClasses) {
122131
registerBean(annotatedClass);
123132
}
124133
}
125134

135+
/**
136+
* Register a bean from the given bean class, deriving its metadata from
137+
* class-declared annotations.
138+
* @param annotatedClass the class of the bean
139+
*/
140+
@SuppressWarnings("unchecked")
126141
public void registerBean(Class<?> annotatedClass) {
127142
registerBean(annotatedClass, null, (Class<? extends Annotation>[]) null);
128143
}
129144

145+
/**
146+
* Register a bean from the given bean class, deriving its metadata from
147+
* class-declared annotations.
148+
* @param annotatedClass the class of the bean
149+
* @param qualifiers specific qualifier annotations to consider,
150+
* in addition to qualifiers at the bean class level
151+
*/
130152
@SuppressWarnings("unchecked")
131153
public void registerBean(Class<?> annotatedClass, Class<? extends Annotation>... qualifiers) {
132154
registerBean(annotatedClass, null, qualifiers);
133155
}
134156

157+
/**
158+
* Register a bean from the given bean class, deriving its metadata from
159+
* class-declared annotations.
160+
* @param annotatedClass the class of the bean
161+
* @param name an explicit name for the bean
162+
* @param qualifiers specific qualifier annotations to consider,
163+
* in addition to qualifiers at the bean class level
164+
*/
135165
@SuppressWarnings("unchecked")
136166
public void registerBean(Class<?> annotatedClass, String name, Class<? extends Annotation>... qualifiers) {
137167
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(annotatedClass);

spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -135,6 +135,16 @@ public void setScopeMetadataResolver(ScopeMetadataResolver scopeMetadataResolver
135135
this.scanner.setScopeMetadataResolver(scopeMetadataResolver);
136136
}
137137

138+
@Override
139+
protected void prepareRefresh() {
140+
this.scanner.clearCache();
141+
super.prepareRefresh();
142+
}
143+
144+
145+
//---------------------------------------------------------------------
146+
// Implementation of AnnotationConfigRegistry
147+
//---------------------------------------------------------------------
138148

139149
/**
140150
* Register one or more annotated classes to be processed.
@@ -163,11 +173,4 @@ public void scan(String... basePackages) {
163173
this.scanner.scan(basePackages);
164174
}
165175

166-
167-
@Override
168-
protected void prepareRefresh() {
169-
this.scanner.clearCache();
170-
super.prepareRefresh();
171-
}
172-
173176
}

spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -158,6 +158,7 @@ public void setId(String id) {
158158
* Set whether it should be allowed to override bean definitions by registering
159159
* a different definition with the same name, automatically replacing the former.
160160
* If not, an exception will be thrown. Default is "true".
161+
* @since 3.0
161162
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
162163
*/
163164
public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding) {
@@ -169,6 +170,7 @@ public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverridi
169170
* try to resolve them.
170171
* <p>Default is "true". Turn this off to throw an exception when encountering
171172
* a circular reference, disallowing them completely.
173+
* @since 3.0
172174
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowCircularReferences
173175
*/
174176
public void setAllowCircularReferences(boolean allowCircularReferences) {
@@ -198,6 +200,10 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
198200
}
199201

200202

203+
//---------------------------------------------------------------------
204+
// ResourceLoader / ResourcePatternResolver override if necessary
205+
//---------------------------------------------------------------------
206+
201207
/**
202208
* This implementation delegates to this context's ResourceLoader if set,
203209
* falling back to the default superclass behavior else.

spring-core/src/main/java/org/springframework/core/env/ConfigurableEnvironment.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,24 +35,24 @@
3535
*
3636
* <h4>Example: adding a new property source with highest search priority</h4>
3737
* <pre class="code">
38-
* ConfigurableEnvironment environment = new StandardEnvironment();
39-
* MutablePropertySources propertySources = environment.getPropertySources();
40-
* Map<String, String> myMap = new HashMap<String, String>();
41-
* myMap.put("xyz", "myValue");
42-
* propertySources.addFirst(new MapPropertySource("MY_MAP", myMap));
38+
* ConfigurableEnvironment environment = new StandardEnvironment();
39+
* MutablePropertySources propertySources = environment.getPropertySources();
40+
* Map<String, String> myMap = new HashMap<String, String>();
41+
* myMap.put("xyz", "myValue");
42+
* propertySources.addFirst(new MapPropertySource("MY_MAP", myMap));
4343
* </pre>
4444
*
4545
* <h4>Example: removing the default system properties property source</h4>
4646
* <pre class="code">
47-
* MutablePropertySources propertySources = environment.getPropertySources();
48-
* propertySources.remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)
47+
* MutablePropertySources propertySources = environment.getPropertySources();
48+
* propertySources.remove(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)
4949
* </pre>
5050
*
5151
* <h4>Example: mocking the system environment for testing purposes</h4>
5252
* <pre class="code">
53-
* MutablePropertySources propertySources = environment.getPropertySources();
54-
* MockPropertySource mockEnvVars = new MockPropertySource().withProperty("xyz", "myValue");
55-
* propertySources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars);
53+
* MutablePropertySources propertySources = environment.getPropertySources();
54+
* MockPropertySource mockEnvVars = new MockPropertySource().withProperty("xyz", "myValue");
55+
* propertySources.replace(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, mockEnvVars);
5656
* </pre>
5757
*
5858
* When an {@link Environment} is being used by an {@code ApplicationContext}, it is
@@ -64,7 +64,6 @@
6464
* org.springframework.context.support.PropertySourcesPlaceholderConfigurer property
6565
* placeholder configurers}.
6666
*
67-
*
6867
* @author Chris Beams
6968
* @since 3.1
7069
* @see StandardEnvironment

spring-core/src/main/java/org/springframework/core/env/Environment.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,8 +77,8 @@ public interface Environment extends PropertyResolver {
7777
* activated by setting {@linkplain AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME
7878
* "spring.profiles.active"} as a system property or by calling
7979
* {@link ConfigurableEnvironment#setActiveProfiles(String...)}.
80-
* <p>If no profiles have explicitly been specified as active, then any {@linkplain
81-
* #getDefaultProfiles() default profiles} will automatically be activated.
80+
* <p>If no profiles have explicitly been specified as active, then any
81+
* {@linkplain #getDefaultProfiles() default profiles} will automatically be activated.
8282
* @see #getDefaultProfiles
8383
* @see ConfigurableEnvironment#setActiveProfiles
8484
* @see AbstractEnvironment#ACTIVE_PROFILES_PROPERTY_NAME

0 commit comments

Comments
 (0)