Hi

You cannot add the template from the same configure method, you need
to add from someplace else

On Wed, Oct 14, 2020 at 11:11 PM CASAUX Nicolas
<nicolas.cas...@soprasteria.com> wrote:
>
> Hello !
>
> I'm trying to experiment with the new route templates features along with 
> spring boot.
> I just tried to create a class with both the template and the route provided 
> in the camel page https://camel.apache.org/manual/latest/route-template.html:
> I'm using Camel 3.5 and springboot 2.3.4
>
> @Component
> public class MyRouteTemplates extends RouteBuilder {
>
>     @Override
>     public void configure() throws Exception {
>         // create a route template with the given name
>         routeTemplate("myTemplate")
>                 // here we define the required input parameters (can have 
> default values)
>                 .templateParameter("name")
>                 .templateParameter("greeting")
>                 .templateParameter("myPeriod", "3s")
>                 // here comes the route in the template
>                 // notice how we use {{name}} to refer to the template 
> parameters
>                 // we can also use {{propertyName}} to refer to property 
> placeholders
>                 .from("timer:{{name}}?period={{myPeriod}}")
>                 .setBody(simple("{{greeting}} ${body}"))
>                 .log("${body}");
>
>         TemplatedRouteBuilder.builder(getContext(), "myTemplate")
>                 .routeId("myCoolRoute")
>                 .parameter("name", "one")
>                 .parameter("greeting", "Hello")
>                 .add();
>     }
> }
>
> When I run "mvn spring-boot:run", I got an error saying that the template 
> cannot be found.
>
> java.lang.IllegalArgumentException: Cannot find RouteTemplate with id 
> myTemplate
>                 at 
> org.apache.camel.impl.DefaultModel.addRouteFromTemplate(DefaultModel.java:207)
>  ~[camel-core-engine-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.impl.DefaultCamelContext.addRouteFromTemplate(DefaultCamelContext.java:188)
>  ~[camel-core-engine-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.builder.TemplatedRouteBuilder.add(TemplatedRouteBuilder.java:104)
>  ~[camel-core-engine-3.5.0.jar:3.5.0]
>                 at 
> fr.sncf.piv.servicechecker.mode.notificationmode.common.routebuilder.MyRoute.configure(MyRoute.java:22)
>  ~[classes/:na]
>                 at 
> org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:483) 
> ~[camel-core-engine-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:430) 
> ~[camel-core-engine-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:405)
>  ~[camel-core-engine-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.impl.engine.AbstractCamelContext.addRoutes(AbstractCamelContext.java:1185)
>  ~[camel-base-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.main.RoutesConfigurer.configureRoutes(RoutesConfigurer.java:93)
>  ~[camel-main-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.spring.boot.CamelSpringBootApplicationListener.onApplicationEvent(CamelSpringBootApplicationListener.java:101)
>  ~[camel-spring-boot-3.5.0.jar:3.5.0]
>                 at 
> org.apache.camel.spring.boot.CamelSpringBootApplicationListener.onApplicationEvent(CamelSpringBootApplicationListener.java:57)
>  ~[camel-spring-boot-3.5.0.jar:3.5.0]
>                 at 
> org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
>  ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
>                 at 
> org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
>  ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
>                 at 
> org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
>  ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
>                 at 
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:404)
>  ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
>                 at 
> org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:361)
>  ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
>                 at 
> org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:898)
>  ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
>                 at 
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:554)
>  ~[spring-context-5.2.9.RELEASE.jar:5.2.9.RELEASE]
>                 at 
> org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
>  ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
>                 at 
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
>  ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
>                 at 
> org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
>  ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
>                 at 
> org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
>  ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
>                 at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:315) 
> ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
>                 at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) 
> ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
>                 at 
> org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) 
> ~[spring-boot-2.3.4.RELEASE.jar:2.3.4.RELEASE]
>
> Is there something wrong with what I'm trying to achieve ?
>
> Thanks in advance for your help ! :)
>
> Regards,
> Nicolas



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to