@@ -446,23 +446,6 @@ ConfigurableApplicationContext initializeBinderContextSimple(String configuratio
446446 binderProducingContext .getBeanFactory ().setConversionService (this .context .getBeanFactory ().getConversionService ());
447447 }
448448
449- List <Class > sourceClasses = new ArrayList <>();
450- sourceClasses .addAll (Arrays .asList (binderType .getConfigurationClasses ()));
451- if (binderProperties .containsKey ("spring.main.sources" )) {
452- String sources = (String ) binderProperties .get ("spring.main.sources" );
453- if (StringUtils .hasText (sources )) {
454- Stream .of (sources .split ("," )).forEach (source -> {
455- try {
456- sourceClasses .add (Thread .currentThread ().getContextClassLoader ().loadClass (source .trim ()));
457- }
458- catch (Exception e ) {
459- throw new IllegalStateException ("Failed to load class " + source , e );
460- }
461- });
462- }
463- }
464-
465- binderProducingContext .register (sourceClasses .toArray (new Class [] {}));
466449 MapPropertySource binderPropertySource = new MapPropertySource (configurationName , binderProperties );
467450 binderProducingContext .getEnvironment ().getPropertySources ().addFirst (binderPropertySource );
468451 binderProducingContext .setDisplayName (configurationName + "_context" );
@@ -502,6 +485,23 @@ public void onApplicationEvent(ApplicationEvent event) {
502485 }
503486 }
504487
488+ // Register the sources classes to the specific binder context after configuring the environment property sources
489+ List <Class > sourceClasses = new ArrayList <>(Arrays .asList (binderType .getConfigurationClasses ()));
490+ if (binderProperties .containsKey ("spring.main.sources" )) {
491+ String sources = (String ) binderProperties .get ("spring.main.sources" );
492+ if (StringUtils .hasText (sources )) {
493+ Stream .of (sources .split ("," )).forEach (source -> {
494+ try {
495+ sourceClasses .add (Thread .currentThread ().getContextClassLoader ().loadClass (source .trim ()));
496+ }
497+ catch (Exception e ) {
498+ throw new IllegalStateException ("Failed to load class " + source , e );
499+ }
500+ });
501+ }
502+ }
503+ binderProducingContext .register (sourceClasses .toArray (new Class [] {}));
504+
505505 if (refresh ) {
506506 if (!useApplicationContextAsParent || "integration" .equals (binderType .getDefaultName ())) {
507507 this .propagateSharedBeans (binderProducingContext , (GenericApplicationContext ) this .context );
0 commit comments