File tree Expand file tree Collapse file tree 2 files changed +20
-10
lines changed
main/java/org/springframework/boot
test/java/org/springframework/boot Expand file tree Collapse file tree 2 files changed +20
-10
lines changed Original file line number Diff line number Diff line change 72
72
import org .springframework .util .ReflectionUtils ;
73
73
import org .springframework .util .StopWatch ;
74
74
import org .springframework .util .StringUtils ;
75
- import org .springframework .web .context .ConfigurableWebApplicationContext ;
76
75
import org .springframework .web .context .WebApplicationContext ;
77
76
import org .springframework .web .context .support .StandardServletEnvironment ;
78
77
@@ -603,15 +602,10 @@ protected ConfigurableApplicationContext createApplicationContext() {
603
602
* @param context the application context
604
603
*/
605
604
protected void postProcessApplicationContext (ConfigurableApplicationContext context ) {
606
- if (this .webEnvironment ) {
607
- if (context instanceof ConfigurableWebApplicationContext ) {
608
- ConfigurableWebApplicationContext configurableContext = (ConfigurableWebApplicationContext ) context ;
609
- if (this .beanNameGenerator != null ) {
610
- configurableContext .getBeanFactory ().registerSingleton (
611
- AnnotationConfigUtils .CONFIGURATION_BEAN_NAME_GENERATOR ,
612
- this .beanNameGenerator );
613
- }
614
- }
605
+ if (this .beanNameGenerator != null ) {
606
+ context .getBeanFactory ().registerSingleton (
607
+ AnnotationConfigUtils .CONFIGURATION_BEAN_NAME_GENERATOR ,
608
+ this .beanNameGenerator );
615
609
}
616
610
if (this .resourceLoader != null ) {
617
611
if (context instanceof GenericApplicationContext ) {
Original file line number Diff line number Diff line change 53
53
import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
54
54
import org .springframework .context .annotation .AnnotationConfigUtils ;
55
55
import org .springframework .context .annotation .Bean ;
56
+ import org .springframework .context .annotation .ComponentScan ;
56
57
import org .springframework .context .annotation .Configuration ;
57
58
import org .springframework .context .event .ContextRefreshedEvent ;
58
59
import org .springframework .context .event .SimpleApplicationEventMulticaster ;
@@ -403,6 +404,21 @@ public void customBeanNameGenerator() throws Exception {
403
404
sameInstance ((Object ) beanNameGenerator ));
404
405
}
405
406
407
+ @ Test
408
+ public void customBeanNameGeneratorWithNonWebApplication () throws Exception {
409
+ TestSpringApplication application = new TestSpringApplication (
410
+ ExampleWebConfig .class );
411
+ application .setWebEnvironment (false );
412
+ BeanNameGenerator beanNameGenerator = new DefaultBeanNameGenerator ();
413
+ application .setBeanNameGenerator (beanNameGenerator );
414
+ this .context = application .run ();
415
+ verify (application .getLoader ()).setBeanNameGenerator (beanNameGenerator );
416
+ assertThat (
417
+ this .context
418
+ .getBean (AnnotationConfigUtils .CONFIGURATION_BEAN_NAME_GENERATOR ),
419
+ sameInstance ((Object ) beanNameGenerator ));
420
+ }
421
+
406
422
@ Test
407
423
public void commandLinePropertySource () throws Exception {
408
424
SpringApplication application = new SpringApplication (ExampleConfig .class );
You can’t perform that action at this time.
0 commit comments