This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/main by this push:
new 2009ad9f9de CAMEL-21359: camel-spring-boot - Add support for
MainListener
2009ad9f9de is described below
commit 2009ad9f9de57b51b75442c78434e3ecb567f2a3
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jan 24 14:10:10 2025 +0100
CAMEL-21359: camel-spring-boot - Add support for MainListener
---
.../camel/spring/boot/CamelAutoConfiguration.java | 21 ++-------------------
.../boot/CamelSpringBootApplicationController.java | 8 ++++++++
2 files changed, 10 insertions(+), 19 deletions(-)
diff --git
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index fca73c19c2a..63c342932ee 100644
---
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -33,7 +33,6 @@ import org.apache.camel.RuntimeCamelException;
import org.apache.camel.clock.Clock;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.component.properties.PropertiesParser;
-import org.apache.camel.main.BaseMainSupport;
import org.apache.camel.main.DefaultConfigurationConfigurer;
import org.apache.camel.main.MainListener;
import org.apache.camel.main.RoutesCollector;
@@ -104,9 +103,9 @@ public class CamelAutoConfiguration {
@Bean(destroyMethod = "")
@ConditionalOnMissingBean(CamelContext.class)
CamelContext camelContext(ApplicationContext applicationContext,
CamelConfigurationProperties config,
- CamelBeanPostProcessor beanPostProcessor,
StartupConditionStrategy startup,
- CamelSpringBootApplicationController controller)
throws Exception {
+ CamelBeanPostProcessor beanPostProcessor,
StartupConditionStrategy startup) throws Exception {
Clock clock = new ResetableClock();
+ CamelSpringBootApplicationController controller = new
CamelSpringBootApplicationController(applicationContext);
CamelContext camelContext = new
SpringBootCamelContext(applicationContext,
config.getSpringboot().isWarnOnEarlyShutdown(), controller);
camelContext.getClock().add(ContextEvents.BOOT, clock);
@@ -288,22 +287,6 @@ public class CamelAutoConfiguration {
}
}
- /**
- * Create controller eager
- */
- @Bean
- CamelSpringBootApplicationController
applicationController(ApplicationContext applicationContext) {
- CamelSpringBootApplicationController controller = new
CamelSpringBootApplicationController(applicationContext);
-
- // setup main listeners eager on controller
- final Map<String, MainListener> listeners =
applicationContext.getBeansOfType(MainListener.class);
- for (MainListener listener : listeners.values()) {
- controller.getMain().addMainListener(listener);
- }
-
- return controller;
- }
-
@Bean
@ConditionalOnMissingBean(RoutesCollector.class)
@ConditionalOnMissingClass("org.apache.camel.spring.boot.endpointdsl.EndpointDslRouteCollector")
diff --git
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java
index 2ce9833a429..4164cdbdeea 100644
---
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java
+++
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java
@@ -21,12 +21,15 @@ import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.main.Main;
+import org.apache.camel.main.MainListener;
import org.apache.camel.main.MainShutdownStrategy;
import org.apache.camel.main.SimpleMainShutdownStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
+import java.util.Map;
+
public class CamelSpringBootApplicationController implements CamelContextAware
{
private static final Logger LOG =
LoggerFactory.getLogger(CamelSpringBootApplicationController.class);
@@ -35,6 +38,11 @@ public class CamelSpringBootApplicationController implements
CamelContextAware {
public CamelSpringBootApplicationController(final ApplicationContext
applicationContext) {
this.main = new CamelSpringMain(applicationContext);
+ // inject main listeners
+ final Map<String, MainListener> listeners =
applicationContext.getBeansOfType(MainListener.class);
+ for (MainListener listener : listeners.values()) {
+ this.main.addMainListener(listener);
+ }
}
public Main getMain() {