Skip to content

Commit 8626a33

Browse files
philwebbsnicoll
authored andcommitted
Polish "Migrate ApplicationContext to common hierarchy"
Users calling the methods will still face problems but at least they will have some guidance. Closes spring-projectsgh-16096
1 parent c432288 commit 8626a33

File tree

1 file changed

+276
-0
lines changed

1 file changed

+276
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/context/AnnotationConfigReactiveWebApplicationContext.java

Lines changed: 276 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616

1717
package org.springframework.boot.web.reactive.context;
1818

19+
import org.springframework.beans.factory.support.BeanNameGenerator;
20+
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
21+
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
1922
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
23+
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
2024
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.context.annotation.ImportResource;
26+
import org.springframework.context.annotation.ScopeMetadataResolver;
2127
import org.springframework.core.env.ConfigurableEnvironment;
2228
import org.springframework.core.io.Resource;
29+
import org.springframework.lang.Nullable;
2330
import org.springframework.stereotype.Component;
2431

2532
/**
@@ -35,13 +42,54 @@
3542
* to deliberately override certain bean definitions via an extra Configuration class.
3643
*
3744
* @author Phillip Webb
45+
* @author Stephane Nicoll
3846
* @since 2.0.0
3947
* @see AnnotationConfigApplicationContext
4048
*/
4149
public class AnnotationConfigReactiveWebApplicationContext
4250
extends AnnotationConfigApplicationContext
4351
implements ConfigurableReactiveWebApplicationContext {
4452

53+
/**
54+
* Create a new AnnotationConfigReactiveWebApplicationContext that needs to be
55+
* populated through {@link #register} calls and then manually {@linkplain #refresh
56+
* refreshed}.
57+
*/
58+
public AnnotationConfigReactiveWebApplicationContext() {
59+
}
60+
61+
/**
62+
* Create a new AnnotationConfigApplicationContext with the given
63+
* DefaultListableBeanFactory.
64+
* @param beanFactory the DefaultListableBeanFactory instance to use for this context
65+
* @since 2.2.0
66+
*/
67+
public AnnotationConfigReactiveWebApplicationContext(
68+
DefaultListableBeanFactory beanFactory) {
69+
super(beanFactory);
70+
}
71+
72+
/**
73+
* Create a new AnnotationConfigApplicationContext, deriving bean definitions from the
74+
* given annotated classes and automatically refreshing the context.
75+
* @param annotatedClasses one or more annotated classes, e.g.
76+
* {@link Configuration @Configuration} classes
77+
* @since 2.2.0
78+
*/
79+
public AnnotationConfigReactiveWebApplicationContext(Class<?>... annotatedClasses) {
80+
super(annotatedClasses);
81+
}
82+
83+
/**
84+
* Create a new AnnotationConfigApplicationContext, scanning for bean definitions in
85+
* the given packages and automatically refreshing the context.
86+
* @param basePackages the packages to check for annotated classes
87+
* @since 2.2.0
88+
*/
89+
public AnnotationConfigReactiveWebApplicationContext(String... basePackages) {
90+
super(basePackages);
91+
}
92+
4593
@Override
4694
protected ConfigurableEnvironment createEnvironment() {
4795
return new StandardReactiveWebEnvironment();
@@ -53,4 +101,232 @@ protected Resource getResourceByPath(String path) {
53101
return new FilteredReactiveWebContextResource(path);
54102
}
55103

104+
/**
105+
* Return the custom {@link BeanNameGenerator} for use with
106+
* {@link AnnotatedBeanDefinitionReader} and/or
107+
* {@link ClassPathBeanDefinitionScanner}, if any.
108+
* @return the bean name generator
109+
* @deprecated since 2.2.0 since this class no longer extends
110+
* {@code AbstractRefreshableConfigApplicationContext}
111+
*/
112+
@Deprecated
113+
protected final BeanNameGenerator getBeanNameGenerator() {
114+
throw new UnsupportedOperationException();
115+
}
116+
117+
/**
118+
* Return the custom {@link ScopeMetadataResolver} for use with
119+
* {@link AnnotatedBeanDefinitionReader} and/or
120+
* {@link ClassPathBeanDefinitionScanner}, if any.
121+
* @return the scope metadata resolver
122+
* @deprecated since 2.2.0 since this class no longer extends
123+
* {@code AbstractRefreshableConfigApplicationContext}
124+
*/
125+
@Deprecated
126+
protected ScopeMetadataResolver getScopeMetadataResolver() {
127+
throw new UnsupportedOperationException();
128+
}
129+
130+
/**
131+
* Register a {@link org.springframework.beans.factory.config.BeanDefinition} for any
132+
* classes specified by {@link #register(Class...)} and scan any packages specified by
133+
* {@link #scan(String...)}.
134+
* <p>
135+
* For any values specified by {@link #setConfigLocation(String)} or
136+
* {@link #setConfigLocations(String[])}, attempt first to load each location as a
137+
* class, registering a {@code BeanDefinition} if class loading is successful, and if
138+
* class loading fails (i.e. a {@code ClassNotFoundException} is raised), assume the
139+
* value is a package and attempt to scan it for annotated classes.
140+
* <p>
141+
* Enables the default set of annotation configuration post processors, such that
142+
* {@code @Autowired}, {@code @Required}, and associated annotations can be used.
143+
* <p>
144+
* Configuration class bean definitions are registered with generated bean definition
145+
* names unless the {@code value} attribute is provided to the stereotype annotation.
146+
* @param beanFactory the bean factory to load bean definitions into
147+
* @see #register(Class...)
148+
* @see #scan(String...)
149+
* @see #setConfigLocation(String)
150+
* @see #setConfigLocations(String[])
151+
* @see AnnotatedBeanDefinitionReader
152+
* @see ClassPathBeanDefinitionScanner
153+
* @deprecated since 2.2.0 since this class no longer extends
154+
* {@code AbstractRefreshableConfigApplicationContext}
155+
*/
156+
@Deprecated
157+
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) {
158+
throw new UnsupportedOperationException();
159+
}
160+
161+
/**
162+
* Build an {@link AnnotatedBeanDefinitionReader} for the given bean factory.
163+
* <p>
164+
* This should be pre-configured with the {@code Environment} (if desired) but not
165+
* with a {@code BeanNameGenerator} or {@code ScopeMetadataResolver} yet.
166+
* @param beanFactory the bean factory to load bean definitions into
167+
* @return the annotated bean definition reader
168+
* @see #getEnvironment()
169+
* @see #getBeanNameGenerator()
170+
* @see #getScopeMetadataResolver()
171+
* @deprecated since 2.2.0 since this class no longer extends
172+
* {@code AbstractRefreshableConfigApplicationContext}
173+
*/
174+
@Deprecated
175+
protected AnnotatedBeanDefinitionReader getAnnotatedBeanDefinitionReader(
176+
DefaultListableBeanFactory beanFactory) {
177+
throw new UnsupportedOperationException();
178+
}
179+
180+
/**
181+
* Build a {@link ClassPathBeanDefinitionScanner} for the given bean factory.
182+
* <p>
183+
* This should be pre-configured with the {@code Environment} (if desired) but not
184+
* with a {@code BeanNameGenerator} or {@code ScopeMetadataResolver} yet.
185+
* @param beanFactory the bean factory to load bean definitions into
186+
* @return the class path bean definition scanner
187+
* @see #getEnvironment()
188+
* @see #getBeanNameGenerator()
189+
* @see #getScopeMetadataResolver()
190+
* @deprecated since 2.2.0 since this class no longer extends
191+
* {@code AbstractRefreshableConfigApplicationContext}
192+
*/
193+
@Deprecated
194+
protected ClassPathBeanDefinitionScanner getClassPathBeanDefinitionScanner(
195+
DefaultListableBeanFactory beanFactory) {
196+
throw new UnsupportedOperationException();
197+
}
198+
199+
/**
200+
* Set the config locations for this application context in init-param style, i.e.
201+
* with distinct locations separated by commas, semicolons or whitespace.
202+
* <p>
203+
* If not set, the implementation may use a default as appropriate.
204+
* @param location the config location
205+
* @deprecated since 2.2.0 since this class no longer extends
206+
* {@code AbstractRefreshableConfigApplicationContext}. Use {@link ImportResource}
207+
* instead.
208+
*/
209+
@Deprecated
210+
public void setConfigLocation(String location) {
211+
throw new UnsupportedOperationException();
212+
}
213+
214+
/**
215+
* Set the config locations for this application context.
216+
* <p>
217+
* If not set, the implementation may use a default as appropriate.
218+
* @param locations the config locations
219+
* @deprecated since 2.2.0 since this class no longer extends
220+
* {@code AbstractRefreshableConfigApplicationContext}. Use {@link ImportResource}
221+
* instead.
222+
*/
223+
@Deprecated
224+
public void setConfigLocations(@Nullable String... locations) {
225+
throw new UnsupportedOperationException();
226+
}
227+
228+
/**
229+
* Return an array of resource locations, referring to the XML bean definition files
230+
* that this context should be built with. Can also include location patterns, which
231+
* will get resolved via a ResourcePatternResolver.
232+
* <p>
233+
* The default implementation returns {@code null}. Subclasses can override this to
234+
* provide a set of resource locations to load bean definitions from.
235+
* @return an array of resource locations, or {@code null} if none
236+
* @see #getResources
237+
* @see #getResourcePatternResolver
238+
* @deprecated since 2.2.0 since this class no longer extends
239+
* {@code AbstractRefreshableConfigApplicationContext}.
240+
*/
241+
@Deprecated
242+
protected String[] getConfigLocations() {
243+
throw new UnsupportedOperationException();
244+
}
245+
246+
/**
247+
* Return the default config locations to use, for the case where no explicit config
248+
* locations have been specified.
249+
* <p>
250+
* The default implementation returns {@code null}, requiring explicit config
251+
* locations.
252+
* @return an array of default config locations, if any
253+
* @see #setConfigLocations
254+
* @deprecated since 2.2.0 since this class no longer extends
255+
* {@code AbstractRefreshableConfigApplicationContext}.
256+
*/
257+
@Deprecated
258+
protected String[] getDefaultConfigLocations() {
259+
throw new UnsupportedOperationException();
260+
}
261+
262+
/**
263+
* Resolve the given path, replacing placeholders with corresponding environment
264+
* property values if necessary. Applied to config locations.
265+
* @param path the original file path
266+
* @return the resolved file path
267+
* @see org.springframework.core.env.Environment#resolveRequiredPlaceholders(String)
268+
* @deprecated since 2.2.0 since this class no longer extends
269+
* {@code AbstractRefreshableConfigApplicationContext}.
270+
*/
271+
@Deprecated
272+
protected String resolvePath(String path) {
273+
throw new UnsupportedOperationException();
274+
}
275+
276+
/**
277+
* Determine whether this context currently holds a bean factory, i.e. has been
278+
* refreshed at least once and not been closed yet.
279+
* @return {@code true} if the context holds a bean factory
280+
* @deprecated since 2.2.0 since this class no longer extends
281+
* {@code AbstractRefreshableConfigApplicationContext}.
282+
*/
283+
@Deprecated
284+
protected final boolean hasBeanFactory() {
285+
return true;
286+
}
287+
288+
/**
289+
* Create an internal bean factory for this context. Called for each
290+
* {@link #refresh()} attempt.
291+
* <p>
292+
* The default implementation creates a
293+
* {@link org.springframework.beans.factory.support.DefaultListableBeanFactory} with
294+
* the {@linkplain #getInternalParentBeanFactory() internal bean factory} of this
295+
* context's parent as parent bean factory. Can be overridden in subclasses, for
296+
* example to customize DefaultListableBeanFactory's settings.
297+
* @return the bean factory for this context
298+
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
299+
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowEagerClassLoading
300+
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowCircularReferences
301+
* @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
302+
* @deprecated since 2.2.0 since this class no longer extends
303+
* {@code AbstractRefreshableConfigApplicationContext}.
304+
*/
305+
@Deprecated
306+
protected DefaultListableBeanFactory createBeanFactory() {
307+
throw new UnsupportedOperationException();
308+
}
309+
310+
/**
311+
* Customize the internal bean factory used by this context. Called for each
312+
* {@link #refresh()} attempt.
313+
* <p>
314+
* The default implementation applies this context's
315+
* {@linkplain #setAllowBeanDefinitionOverriding "allowBeanDefinitionOverriding"} and
316+
* {@linkplain #setAllowCircularReferences "allowCircularReferences"} settings, if
317+
* specified. Can be overridden in subclasses to customize any of
318+
* {@link DefaultListableBeanFactory}'s settings.
319+
* @param beanFactory the newly created bean factory for this context
320+
* @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
321+
* @see DefaultListableBeanFactory#setAllowCircularReferences
322+
* @see DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
323+
* @see DefaultListableBeanFactory#setAllowEagerClassLoading
324+
* @deprecated since 2.2.0 since this class no longer extends
325+
* {@code AbstractRefreshableConfigApplicationContext}.
326+
*/
327+
@Deprecated
328+
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) {
329+
throw new UnsupportedOperationException();
330+
}
331+
56332
}

0 commit comments

Comments
 (0)