2424import java .util .Set ;
2525import javax .servlet .ServletContext ;
2626
27+ import org .springframework .beans .BeanUtils ;
2728import org .springframework .beans .BeansException ;
2829import org .springframework .beans .TypeConverter ;
2930import org .springframework .beans .factory .BeanFactory ;
4344import org .springframework .core .env .StandardEnvironment ;
4445import org .springframework .core .io .Resource ;
4546import org .springframework .core .io .support .ResourcePatternResolver ;
47+ import org .springframework .util .ClassUtils ;
4648import org .springframework .util .ObjectUtils ;
4749import org .springframework .web .context .WebApplicationContext ;
4850import org .springframework .web .context .support .ServletContextResourcePatternResolver ;
4951
5052/**
51- * A mock WebApplicationContext that accepts registrations of object instances.
53+ * A stub WebApplicationContext that accepts registrations of object instances.
5254 *
53- * <p>As registered object instances are instantiated and initialized
54- * externally, there is no wiring, bean initialization, lifecycle events, as
55- * well as no pre-processing and post-processing hooks typically associated with
56- * beans managed by an {@link ApplicationContext}. Just a simple lookup into a
55+ * <p>As registered object instances are instantiated and initialized externally,
56+ * there is no wiring, bean initialization, lifecycle events, as well as no
57+ * pre-processing and post-processing hooks typically associated with beans
58+ * managed by an {@link ApplicationContext}. Just a simple lookup into a
5759 * {@link StaticListableBeanFactory}.
5860 *
5961 * @author Rossen Stoyanchev
62+ * @author Juergen Hoeller
6063 * @since 3.2
6164 */
6265class StubWebApplicationContext implements WebApplicationContext {
@@ -78,9 +81,6 @@ class StubWebApplicationContext implements WebApplicationContext {
7881 private final ResourcePatternResolver resourcePatternResolver ;
7982
8083
81- /**
82- * Class constructor.
83- */
8484 public StubWebApplicationContext (ServletContext servletContext ) {
8585 this .servletContext = servletContext ;
8686 this .resourcePatternResolver = new ServletContextResourcePatternResolver (servletContext );
@@ -322,7 +322,7 @@ public String getMessage(MessageSourceResolvable resolvable, Locale locale) thro
322322
323323 @ Override
324324 public ClassLoader getClassLoader () {
325- return null ;
325+ return ClassUtils . getDefaultClassLoader () ;
326326 }
327327
328328 @ Override
@@ -366,65 +366,61 @@ public Object initializeBean(Object existingBean, String beanName) throws BeansE
366366
367367 @ Override
368368 public <T > T createBean (Class <T > beanClass ) {
369- throw new UnsupportedOperationException ( );
369+ return BeanUtils . instantiate ( beanClass );
370370 }
371371
372372 @ Override
373373 @ SuppressWarnings ("rawtypes" )
374- public Object createBean (Class beanClass , int autowireMode , boolean dependencyCheck ) {
375- throw new UnsupportedOperationException ( );
374+ public Object createBean (Class <?> beanClass , int autowireMode , boolean dependencyCheck ) {
375+ return BeanUtils . instantiate ( beanClass );
376376 }
377377
378378 @ Override
379379 @ SuppressWarnings ("rawtypes" )
380- public Object autowire (Class beanClass , int autowireMode , boolean dependencyCheck ) {
381- throw new UnsupportedOperationException ( );
380+ public Object autowire (Class <?> beanClass , int autowireMode , boolean dependencyCheck ) {
381+ return BeanUtils . instantiate ( beanClass );
382382 }
383383
384384 @ Override
385385 public void autowireBean (Object existingBean ) throws BeansException {
386- throw new UnsupportedOperationException ();
387386 }
388387
389388 @ Override
390389 public void autowireBeanProperties (Object existingBean , int autowireMode , boolean dependencyCheck ) {
391- throw new UnsupportedOperationException ();
392390 }
393391
394392 @ Override
395393 public Object configureBean (Object existingBean , String beanName ) {
396- throw new UnsupportedOperationException () ;
394+ return existingBean ;
397395 }
398396
399397 @ Override
400398 public Object resolveDependency (DependencyDescriptor descriptor , String beanName ) {
401- throw new UnsupportedOperationException ();
399+ throw new UnsupportedOperationException ("Dependency resolution not supported" );
402400 }
403401
404402 @ Override
405403 public Object resolveDependency (DependencyDescriptor descriptor , String beanName ,
406404 Set <String > autowiredBeanNames , TypeConverter typeConverter ) {
407- throw new UnsupportedOperationException ();
405+ throw new UnsupportedOperationException ("Dependency resolution not supported" );
408406 }
409407
410408 @ Override
411409 public void applyBeanPropertyValues (Object existingBean , String beanName ) throws BeansException {
412- throw new UnsupportedOperationException ();
413410 }
414411
415412 @ Override
416413 public Object applyBeanPostProcessorsBeforeInitialization (Object existingBean , String beanName ) {
417- throw new UnsupportedOperationException () ;
414+ return existingBean ;
418415 }
419416
420417 @ Override
421418 public Object applyBeanPostProcessorsAfterInitialization (Object existingBean , String beanName ) {
422- throw new UnsupportedOperationException () ;
419+ return existingBean ;
423420 }
424421
425422 @ Override
426423 public void destroyBean (Object existingBean ) {
427- throw new UnsupportedOperationException ();
428424 }
429425 }
430426
0 commit comments