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 2022/08/03 04:18:43 UTC

[camel] branch main updated: CAMEL-18331: Endpoint bean added via beans.xml are parsed twice (#8096)

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.git


The following commit(s) were added to refs/heads/main by this push:
     new 4cc2fccef44 CAMEL-18331: Endpoint bean added via beans.xml are parsed twice (#8096)
4cc2fccef44 is described below

commit 4cc2fccef4463e4ec903ffa43a8303fe00363a81
Author: Luigi De Masi <55...@users.noreply.github.com>
AuthorDate: Wed Aug 3 06:18:38 2022 +0200

    CAMEL-18331: Endpoint bean added via beans.xml are parsed twice (#8096)
---
 .../spring/xml/handler/CamelNamespaceHandler.java  |  3 +-
 .../spring/SpringEndpointRegistrationTest.java     | 43 ++++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java
index 88eb09c0c65..0c3a58eb16b 100644
--- a/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring-xml/src/main/java/org/apache/camel/spring/xml/handler/CamelNamespaceHandler.java
@@ -754,8 +754,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
             } catch (Exception e) {
                 // Do nothing here
             }
-            parserContext.registerBeanComponent(new BeanComponentDefinition(definition, id));
+            parserContext.registerComponent(new BeanComponentDefinition(definition, id));
         }
     }
-
 }
diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringEndpointRegistrationTest.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringEndpointRegistrationTest.java
new file mode 100644
index 00000000000..8fb6504a9e1
--- /dev/null
+++ b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringEndpointRegistrationTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringEndpointRegistrationTest extends SpringEndpointPropertyTest {
+
+    /**
+     * This test fail during initialization if a bean is registered twice with the same id This is for CAMEL-18331
+     */
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new NoRebindClassPathXmlApplicationContext("org/apache/camel/spring/SpringEndpointPropertyTest.xml");
+    }
+
+    class NoRebindClassPathXmlApplicationContext extends ClassPathXmlApplicationContext {
+        public NoRebindClassPathXmlApplicationContext(String configLocation) throws BeansException {
+            super((ApplicationContext) null);
+            this.setAllowBeanDefinitionOverriding(false);
+            this.setConfigLocations(new String[] { configLocation });
+            this.refresh();
+        }
+    }
+}