@@ -438,23 +438,6 @@ ConfigurableApplicationContext initializeBinderContextSimple(String configuratio
438438 binderProducingContext .getBeanFactory ().setConversionService (this .context .getBeanFactory ().getConversionService ());
439439 }
440440
441- List <Class > sourceClasses = new ArrayList <>();
442- sourceClasses .addAll (Arrays .asList (binderType .getConfigurationClasses ()));
443- if (binderProperties .containsKey ("spring.main.sources" )) {
444- String sources = (String ) binderProperties .get ("spring.main.sources" );
445- if (StringUtils .hasText (sources )) {
446- Stream .of (sources .split ("," )).forEach (source -> {
447- try {
448- sourceClasses .add (Thread .currentThread ().getContextClassLoader ().loadClass (source .trim ()));
449- }
450- catch (Exception e ) {
451- throw new IllegalStateException ("Failed to load class " + source , e );
452- }
453- });
454- }
455- }
456-
457- binderProducingContext .register (sourceClasses .toArray (new Class [] {}));
458441 MapPropertySource binderPropertySource = new MapPropertySource (configurationName , binderProperties );
459442 binderProducingContext .getEnvironment ().getPropertySources ().addFirst (binderPropertySource );
460443 binderProducingContext .setDisplayName (configurationName + "_context" );
@@ -494,6 +477,23 @@ public void onApplicationEvent(ApplicationEvent event) {
494477 }
495478 }
496479
480+ // Register the sources classes to the specific binder context after configuring the environment property sources
481+ List <Class > sourceClasses = new ArrayList <>(Arrays .asList (binderType .getConfigurationClasses ()));
482+ if (binderProperties .containsKey ("spring.main.sources" )) {
483+ String sources = (String ) binderProperties .get ("spring.main.sources" );
484+ if (StringUtils .hasText (sources )) {
485+ Stream .of (sources .split ("," )).forEach (source -> {
486+ try {
487+ sourceClasses .add (Thread .currentThread ().getContextClassLoader ().loadClass (source .trim ()));
488+ }
489+ catch (Exception e ) {
490+ throw new IllegalStateException ("Failed to load class " + source , e );
491+ }
492+ });
493+ }
494+ }
495+ binderProducingContext .register (sourceClasses .toArray (new Class [] {}));
496+
497497 if (refresh ) {
498498 if (!useApplicationContextAsParent || "integration" .equals (binderType .getDefaultName ())) {
499499 this .propagateSharedBeans (binderProducingContext , (GenericApplicationContext ) this .context );
0 commit comments