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-examples.git
The following commit(s) were added to refs/heads/main by this push:
new cfab688 Introduce profiles in routetemplate example (#62)
cfab688 is described below
commit cfab688014d16690b1d2aa25dbfc5ce884266564
Author: Marco Carletti <[email protected]>
AuthorDate: Wed May 25 13:28:21 2022 +0200
Introduce profiles in routetemplate example (#62)
* Introduce profiles in routetemplate example
* Revert the title
---
routetemplate/README.adoc | 6 +++++-
.../src/main/java/sample/camel/MyRouteTemplates.java | 5 ++++-
.../src/main/java/sample/camel/MyTemplateBuilder.java | 5 ++++-
.../{application.yaml => application-xml.yaml} | 2 --
routetemplate/src/main/resources/application.yaml | 17 ++++-------------
5 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/routetemplate/README.adoc b/routetemplate/README.adoc
index a0ca5fe..fd966b2 100644
--- a/routetemplate/README.adoc
+++ b/routetemplate/README.adoc
@@ -14,7 +14,7 @@ An alternative to create routes is from Java which is done in
the `MyTemplateBui
See the `MyCamelApplication.java` where you can change the source to use java
instead of property file for the template parameters.
-In case you would like to see how to create rules from a route template in
Java, simply uncomment the annotation `@Component` in the classes
`MyTemplateBuilder` and `MyRouteTemplates` to allow Spring Boot to
automatically discover them.
+In case you would like to see how to create rules from a route template in
Java, you can use the `java` Spring profile so that the classes
`MyTemplateBuilder` and `MyRouteTemplates` will be automatically discovered.
=== Build
@@ -29,7 +29,11 @@ $ mvn compile
You can run this example using
----
+#to use xml template
$ mvn spring-boot:run
+
+#to use java template
+$ mvn spring-boot:run -Dspring-boot.run.profiles=java
----
=== Help and contributions
diff --git a/routetemplate/src/main/java/sample/camel/MyRouteTemplates.java
b/routetemplate/src/main/java/sample/camel/MyRouteTemplates.java
index dff6fa3..d97f55e 100644
--- a/routetemplate/src/main/java/sample/camel/MyRouteTemplates.java
+++ b/routetemplate/src/main/java/sample/camel/MyRouteTemplates.java
@@ -18,12 +18,15 @@ package sample.camel;
import org.apache.camel.builder.RouteBuilder;
+import org.springframework.context.annotation.Profile;
+
/**
* Route templates using {@link RouteBuilder} which allows
* us to define a number of templates (parameterized routes)
* which we can create routes from.
*/
-//@org.springframework.stereotype.Component
[email protected]
+@Profile("java")
public class MyRouteTemplates extends RouteBuilder {
@Override
diff --git a/routetemplate/src/main/java/sample/camel/MyTemplateBuilder.java
b/routetemplate/src/main/java/sample/camel/MyTemplateBuilder.java
index cf6e5d7..5228be7 100644
--- a/routetemplate/src/main/java/sample/camel/MyTemplateBuilder.java
+++ b/routetemplate/src/main/java/sample/camel/MyTemplateBuilder.java
@@ -18,7 +18,10 @@ package sample.camel;
import org.apache.camel.builder.RouteBuilder;
-//@org.springframework.stereotype.Component
+import org.springframework.context.annotation.Profile;
+
[email protected]
+@Profile("java")
public class MyTemplateBuilder extends RouteBuilder {
/**
diff --git a/routetemplate/src/main/resources/application.yaml
b/routetemplate/src/main/resources/application-xml.yaml
similarity index 98%
copy from routetemplate/src/main/resources/application.yaml
copy to routetemplate/src/main/resources/application-xml.yaml
index 690d146..ab0e040 100644
--- a/routetemplate/src/main/resources/application.yaml
+++ b/routetemplate/src/main/resources/application-xml.yaml
@@ -17,9 +17,7 @@
camel:
springboot:
- name: MyCamel
routes-include-pattern: classpath:mycamel/*.xml
-
route-template:
config:
-0.template-id: myXmlTemplate
diff --git a/routetemplate/src/main/resources/application.yaml
b/routetemplate/src/main/resources/application.yaml
index 690d146..e9fc3f4 100644
--- a/routetemplate/src/main/resources/application.yaml
+++ b/routetemplate/src/main/resources/application.yaml
@@ -15,19 +15,10 @@
# limitations under the License.
#
+spring:
+ profiles:
+ active: xml
+
camel:
springboot:
name: MyCamel
- routes-include-pattern: classpath:mycamel/*.xml
-
- route-template:
- config:
- -0.template-id: myXmlTemplate
- -0.route-id: first
- -0.name: one
- -0.greeting: Hello
- -1.template-id: myXmlTemplate
- -1.route-id: second
- -1.name: deux
- -1.greeting: Bonjour
- -1.my-period: 5s