This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-spring-boot-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git
The following commit(s) were added to refs/heads/camel-spring-boot-3.20.x by
this push:
new b35f172a5bc CAMEL-18862: camel-spring-boot - No need for speical
routes collector can use default
b35f172a5bc is described below
commit b35f172a5bc7a9615beed2a6ed9c4c5b84112a8a
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Jan 6 19:53:26 2023 +0100
CAMEL-18862: camel-spring-boot - No need for speical routes collector can
use default
---
.../camel/spring/boot/CamelAutoConfiguration.java | 6 +-
.../spring/boot/SpringBootRoutesCollector.java | 42 ------------
...urationPostConstructAddRouteToRegistryTest.java | 77 ++++++++++++++++++++++
.../endpointdsl/EndpointDslAutoConfiguration.java | 8 ++-
.../endpointdsl/EndpointDslRouteCollector.java | 11 +---
5 files changed, 89 insertions(+), 55 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 9270c586ac9..928b818ce8c 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
@@ -30,6 +30,7 @@ import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.component.properties.PropertiesParser;
import org.apache.camel.main.DefaultConfigurationConfigurer;
+import org.apache.camel.main.DefaultRoutesCollector;
import org.apache.camel.main.RoutesCollector;
import org.apache.camel.model.Model;
import org.apache.camel.spi.BeanRepository;
@@ -199,8 +200,9 @@ public class CamelAutoConfiguration {
@Bean
@ConditionalOnMissingBean(RoutesCollector.class)
@ConditionalOnMissingClass("org.apache.camel.spring.boot.endpointdsl.EndpointDslRouteCollector")
- RoutesCollector routesCollector(ApplicationContext applicationContext) {
- return new SpringBootRoutesCollector(applicationContext);
+ RoutesCollector routesCollector() {
+ // default collector works with spring boot
+ return new DefaultRoutesCollector();
}
@Bean
diff --git
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
b/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
deleted file mode 100644
index 594bf1087b1..00000000000
---
a/core/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/SpringBootRoutesCollector.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.spring.boot;
-
-import java.util.Collection;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.main.DefaultRoutesCollector;
-import org.springframework.context.ApplicationContext;
-
-/**
- * Spring Boot {@link org.apache.camel.main.RoutesCollector}.
- */
-public class SpringBootRoutesCollector extends DefaultRoutesCollector {
-
- private final ApplicationContext applicationContext;
-
- public SpringBootRoutesCollector(ApplicationContext applicationContext) {
- this.applicationContext = applicationContext;
- }
-
- @Override
- protected <T> Collection<T> findByType(CamelContext camelContext, Class<T>
type) {
- // lookup in application context
- return applicationContext.getBeansOfType(type, true, true).values();
- }
-
-}
diff --git
a/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelConfigurationPostConstructAddRouteToRegistryTest.java
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelConfigurationPostConstructAddRouteToRegistryTest.java
new file mode 100644
index 00000000000..0f833adfb6d
--- /dev/null
+++
b/core/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/CamelConfigurationPostConstructAddRouteToRegistryTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.boot;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+
+@DirtiesContext
+@CamelSpringBootTest
+@EnableAutoConfiguration
+@SpringBootTest(classes = {
+ CamelAutoConfiguration.class,
+ CamelConfigurationPostConstructAddRouteToRegistryTest.Config.class
+})
+public class CamelConfigurationPostConstructAddRouteToRegistryTest {
+
+ @Configuration
+ static class Config {
+
+ @Autowired
+ CamelContext camelContext;
+
+ @PostConstruct
+ public void doPost() {
+ camelContext.getRegistry().bind("myExtraRoute", new RouteBuilder()
{
+ @Override
+ public void configure() throws Exception {
+ from("direct:extra")
+ .to("mock:extra");
+ }
+ });
+ }
+
+ }
+
+ @Autowired
+ CamelContext camelContext;
+
+ @Autowired
+ ProducerTemplate producerTemplate;
+
+ @Test
+ public void shouldAddRoute() throws Exception {
+ MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:extra",
MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(1);
+
+ producerTemplate.sendBody("direct:extra", "Hello World");
+
+ mockEndpoint.assertIsSatisfied();
+ }
+
+}
diff --git
a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
index 2626428843b..f67d07c4212 100644
---
a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
+++
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslAutoConfiguration.java
@@ -18,7 +18,6 @@ package org.apache.camel.spring.boot.endpointdsl;
import org.apache.camel.main.RoutesCollector;
import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
@@ -27,9 +26,12 @@ import org.springframework.context.annotation.Role;
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class EndpointDslAutoConfiguration {
+ /**
+ * Special routes collector when using Endpoint DSL.
+ */
@Bean
- RoutesCollector endpointDslRoutesCollector(ApplicationContext
applicationContext) {
- return new EndpointDslRouteCollector(applicationContext);
+ RoutesCollector endpointDslRoutesCollector() {
+ return new EndpointDslRouteCollector();
}
}
diff --git
a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
index d5d82c7d7b8..9b25d3cd7c7 100644
---
a/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
+++
b/dsl-starter/camel-endpointdsl-starter/src/main/java/org/apache/camel/spring/boot/endpointdsl/EndpointDslRouteCollector.java
@@ -24,18 +24,13 @@ import org.apache.camel.CamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.builder.endpoint.EndpointRouteBuilder;
import org.apache.camel.builder.endpoint.LambdaEndpointRouteBuilder;
-import org.apache.camel.spring.boot.SpringBootRoutesCollector;
-import org.springframework.context.ApplicationContext;
+import org.apache.camel.main.DefaultRoutesCollector;
/**
- * Enhanced {@link SpringBootRoutesCollector} that supports Endpoint DSL with
the
+ * Enhanced {@link org.apache.camel.main.RoutesCollector} that supports
Endpoint DSL with the
* lambda style {@link LambdaEndpointRouteBuilder}.
*/
-public class EndpointDslRouteCollector extends SpringBootRoutesCollector {
-
- public EndpointDslRouteCollector(ApplicationContext applicationContext) {
- super(applicationContext);
- }
+public class EndpointDslRouteCollector extends DefaultRoutesCollector {
@Override
protected Collection<RoutesBuilder>
collectAdditionalRoutesFromRegistry(CamelContext camelContext, String
excludePattern, String includePattern) {