diff --git a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java index 6a797914d0..5fffcc7ffc 100644 --- a/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java +++ b/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binder/DefaultBinderFactory.java @@ -510,8 +510,10 @@ public void onApplicationEvent(ApplicationEvent event) { } } - // Register the sources classes to the specific binder context after configuring the environment property sources - List sourceClasses = new ArrayList<>(Arrays.asList(binderType.getConfigurationClasses())); + // Modified registration: first user classes (spring.main.sources) and then binder classes + List sourceClasses = new ArrayList<>(); + + // First register user classes if defined in spring.main.sources if (binderProperties.containsKey("spring.main.sources")) { String sources = (String) binderProperties.get("spring.main.sources"); if (StringUtils.hasText(sources)) { @@ -525,6 +527,10 @@ public void onApplicationEvent(ApplicationEvent event) { }); } } + + // Then add binder configuration classes + sourceClasses.addAll(Arrays.asList(binderType.getConfigurationClasses())); + binderProducingContext.register(sourceClasses.toArray(new Class[] {})); if (refresh) {