camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Configuring database with jdbc
Date Wed, 09 Jul 2014 13:20:48 GMT
Hi

You are mixing spring xml and starting Apache Camel from a java main
class. Basically you do not start Spring as well.

So either remove spring and register the datasource in SimpleRegistry
which you pass into the DefaultCamelContext constructor.

Or include spring on startup.

There is a Main class from Camel that can load spring also. See the
Main from camel-spring.

See this link
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html

On Wed, Jul 9, 2014 at 2:05 PM, Licia <alicia.parisse@gmail.com> wrote:
> Here is my* spring configuration *:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:jdbc="http://www.springframework.org/schema/jdbc"
>        xmlns:camel="http://camel.apache.org/schema/spring"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="
>                 http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>                 http://www.springframework.org/schema/jdbc
> http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
>                 http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
>
>          <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
>                 destroy-method="close">
>                 <property name="url" value="jdbc:mysql://172.27.178.73:3306/db" />
>                 <property name="driverClassName" value="com.mysql.jdbc.Driver" />
>                 <property name="username" value="dev" />
>                 <property name="password" value="mypassword" />
>         </bean>
>
> </beans>
>
>
> Now, my *route*
>
> public class XmlRoute extends RouteBuilder
> {
>
>         public void configure() throws Exception
>         {
>                 //Transforming xml into database
>                 from ("file:src/data/xmlTest")
>                         .split(xpath("/tabnames/tabname/subTrajectory/month"))
>                         .filter().xpath("/month[@name=\"janvier\"]")
>                         .setHeader("lic", xpath("/month/@nbWorkedDays"))
>                     .setHeader("min", xpath("/month/amount[@type=\"ca\"]/month/text()"))
>                     .setBody(simple("select * from projects where license = ${header.lic}
> and id > ${header.min} order by id"))
>                         .to("jdbc:dataSource?useHeadersAsParameters=true");
>
>
>         }
> }
>
> Finally* my main* (maybe it's from there)
> public static void main( String[] args ) throws Exception
>    {
>
>         //Creating the context
>         CamelContext  myContext = new DefaultCamelContext();
>
>         //Configuring the route
>         XmlRoute myRoute = new XmlRoute();
>
>         myContext.addRoutes(myRoute);
>
>         //Launching the context
>         myContext.start();
>         //Pausing to let the route do its work
>         Thread.sleep(10000);
>         //Stopping the context
>         myContext.stop();
>
>     }
>
>
> The *exception* thrown are :
> Exception in thread "main" org.apache.camel.FailedToCreateRouteException:
> Failed to create route route1 at: >>> Split[xpath{XPath:
> /tabnames/tabname/subTrajectory/month} ->
> [Filter[xpath{/month[@name="janvier"]} -> [SetHeader[lic, xpath{XPath:
> /month/@nbWorkedDays}], SetHeader[min, xpath{XPath:
> /month/amount[@type="ca"]/month/text()}], SetBody[simple{Simple: select *
> from projects where license = ${header.lic} and id > ${header.min} order by
> id}], To[jdbc:dataSource?useHeadersAsParameters=true],
> To[log:toto?level=ERROR]]]]] <<< in route:
> Route(route1)[[From[file:src/data/xmlTest]] -> [Split[xpath{... because of
> Failed to resolve endpoint: jdbc://dataSource?useHeadersAsParameters=true
> due to: No bean could be found in the registry for: dataSource of type:
> javax.sql.DataSource
>         at
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:910)
>         at
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:175)
>         at
> org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:778)
>         at
> org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:2041)
>         at
> org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:1791)
>         at
> org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:1665)
>         at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
>         at
> org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:1633)
>         at com.sopra.camelProject.FileCopier.main(FileCopier.java:38)
> Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to
> resolve endpoint: jdbc://dataSource?useHeadersAsParameters=true due to: No
> bean could be found in the registry for: dataSource of type:
> javax.sql.DataSource
>         at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:532)
>         at
> org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:71)
>         at
> org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:190)
>         at
> org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:106)
>         at
> org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:112)
>         at
> org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:61)
>         at
> org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:55)
>         at
> org.apache.camel.model.ProcessorDefinition.createProcessor(ProcessorDefinition.java:459)
>         at
> org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:428)
>         at
> org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:158)
>         at
> org.apache.camel.model.ProcessorDefinition.createChildProcessor(ProcessorDefinition.java:177)
>         at
> org.apache.camel.model.FilterDefinition.createFilterProcessor(FilterDefinition.java:72)
>         at
> org.apache.camel.model.FilterDefinition.createProcessor(FilterDefinition.java:66)
>         at
> org.apache.camel.model.FilterDefinition.createProcessor(FilterDefinition.java:34)
>         at
> org.apache.camel.model.ProcessorDefinition.createProcessor(ProcessorDefinition.java:459)
>         at
> org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:428)
>         at
> org.apache.camel.model.ProcessorDefinition.createOutputsProcessor(ProcessorDefinition.java:158)
>         at
> org.apache.camel.model.ProcessorDefinition.createChildProcessor(ProcessorDefinition.java:177)
>         at
> org.apache.camel.model.SplitDefinition.createProcessor(SplitDefinition.java:101)
>         at
> org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:499)
>         at
> org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:212)
>         at
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:907)
>         ... 8 more
> Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in
> the registry for: dataSource of type: javax.sql.DataSource
>         at
> org.apache.camel.util.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:151)
>         at
> org.apache.camel.component.jdbc.JdbcComponent.createEndpoint(JdbcComponent.java:49)
>         at
> org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:123)
>         at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:512)
>         ... 29 more
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Configuring-database-with-jdbc-tp5753574p5753592.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Mime
View raw message