You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/10/28 12:28:12 UTC
[camel] branch master updated: CAMEL-14075: Upgrade to Spring Boot
2.2.0. Isolte fix to camel-spring and camel-spring-boot
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new feca251 CAMEL-14075: Upgrade to Spring Boot 2.2.0. Isolte fix to camel-spring and camel-spring-boot
feca251 is described below
commit feca251059401b47ebac438c8fad3421e7bff25b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Oct 28 13:13:43 2019 +0100
CAMEL-14075: Upgrade to Spring Boot 2.2.0. Isolte fix to camel-spring and camel-spring-boot
---
.../camel/spring/boot/CamelAutoConfiguration.java | 4 +--
.../boot/CamelSpringBootBeanPostProcessor.java | 30 ++++++++++++++++++++++
.../camel/spring/CamelBeanPostProcessor.java | 26 +++++++++++--------
.../main/java/org/apache/camel/BindToRegistry.java | 5 ++++
.../impl/engine/DefaultCamelBeanPostProcessor.java | 19 +++++++++++---
5 files changed, 66 insertions(+), 18 deletions(-)
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index b1c73ea..2336ce6 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -240,9 +240,7 @@ public class CamelAutoConfiguration {
*/
@Bean
CamelBeanPostProcessor camelBeanPostProcessor(ApplicationContext applicationContext) {
- CamelBeanPostProcessor processor = new CamelBeanPostProcessor();
- processor.setApplicationContext(applicationContext);
- return processor;
+ return new CamelSpringBootBeanPostProcessor(applicationContext);
}
}
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootBeanPostProcessor.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootBeanPostProcessor.java
new file mode 100644
index 0000000..0fcf5a7
--- /dev/null
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootBeanPostProcessor.java
@@ -0,0 +1,30 @@
+/*
+ * 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 org.apache.camel.spring.CamelBeanPostProcessor;
+import org.springframework.context.ApplicationContext;
+
+public final class CamelSpringBootBeanPostProcessor extends CamelBeanPostProcessor {
+
+ public CamelSpringBootBeanPostProcessor(ApplicationContext applicationContext) {
+ setApplicationContext(applicationContext);
+ // do not support @BindToRegistry as spring boot has its own set of annotations for this
+ setBindToRegistrySupported(false);
+ }
+
+}
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
index 92963e5..0b5df53 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
@@ -59,6 +59,8 @@ public class CamelBeanPostProcessor implements org.apache.camel.spi.CamelBeanPos
private ApplicationContext applicationContext;
@XmlTransient
private String camelId;
+ @XmlTransient
+ private boolean bindToRegistrySupported;
// must use a delegate, as we cannot extend DefaultCamelBeanPostProcessor, as this will cause the
// XSD schema generator to include the DefaultCamelBeanPostProcessor as a type, which we do not want to
@@ -91,21 +93,16 @@ public class CamelBeanPostProcessor implements org.apache.camel.spi.CamelBeanPos
return false;
}
- if (beanName != null && beanName.startsWith("org.springframework")) {
- // do not let camel post process spring beans
- // (no point and there are some problems see CAMEL-14075)
- return false;
- }
- if (bean.getClass().getTypeName().startsWith("org.springframework")) {
- // do not let camel post process spring beans
- // (no point and there are some problems see CAMEL-14075)
- return false;
- }
-
return super.canPostProcessBean(bean, beanName);
}
@Override
+ protected boolean bindToRegistrySupported() {
+ // do not support @BindToRegistry as spring and spring-boot has its own set of annotations for this
+ return false;
+ }
+
+ @Override
public CamelPostProcessorHelper getPostProcessorHelper() {
// lets lazily create the post processor
if (camelPostProcessorHelper == null) {
@@ -209,4 +206,11 @@ public class CamelBeanPostProcessor implements org.apache.camel.spi.CamelBeanPos
this.camelId = camelId;
}
+ public boolean isBindToRegistrySupported() {
+ return bindToRegistrySupported;
+ }
+
+ public void setBindToRegistrySupported(boolean bindToRegistrySupported) {
+ this.bindToRegistrySupported = bindToRegistrySupported;
+ }
}
diff --git a/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java b/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
index a95e611..bfed217 100644
--- a/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
+++ b/core/camel-api/src/main/java/org/apache/camel/BindToRegistry.java
@@ -25,6 +25,11 @@ import java.lang.annotation.Target;
/**
* Used for binding a bean to the registry.
*
+ * This annotation is not supported with camel-spring or camel-spring-boot as they have
+ * their own set of annotations for registering beans in spring bean registry.
+ * Instead this annotation is intended for Camel standalone such as camel-main or camel-quarkus
+ * or similar runtimes.
+ *
* If no name is specified then the bean will have its name auto computed based on the
* class name, field name, or method name where the annotation is configured.
*/
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java
index 5fb4c0e..29c16cf 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/DefaultCamelBeanPostProcessor.java
@@ -85,10 +85,13 @@ public class DefaultCamelBeanPostProcessor implements CamelBeanPostProcessor {
return bean;
}
- injectClass(bean, beanName);
- injectNestedClasses(bean, beanName);
- injectBindToRegistryFields(bean, beanName);
- injectBindToRegistryMethods(bean, beanName);
+ if (bindToRegistrySupported()) {
+ injectClass(bean, beanName);
+ injectNestedClasses(bean, beanName);
+ injectBindToRegistryFields(bean, beanName);
+ injectBindToRegistryMethods(bean, beanName);
+ }
+
injectFields(bean, beanName);
injectMethods(bean, beanName);
@@ -145,6 +148,14 @@ public class DefaultCamelBeanPostProcessor implements CamelBeanPostProcessor {
return bean != null;
}
+ /**
+ * Whether support for the annotation {@link BindToRegistry} is supported.
+ * This is only intended for standalone runtimes such as camel-main, camel-quarkus, etc.
+ */
+ protected boolean bindToRegistrySupported() {
+ return true;
+ }
+
protected boolean canSetCamelContext(Object bean, String beanName) {
if (bean instanceof CamelContextAware) {
CamelContextAware camelContextAware = (CamelContextAware) bean;