У меня есть источник данных, определенный в моем файле application.properties как:
spring.datasource.url = jdbc:mysql://localhost:3306/world?useSSL=false
spring.datasource.username = root
spring.datasource.password = password
Однако, когда я пытаюсь запустить свой camelroute, я получаю эту ошибку: «В реестре не найден бинfor: источник данных типа: javax.sql.DataSource ".Я всегда настраивал источник данных весной, используя файл application.properties без проблем.
Полный журнал ошибок:
org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: Failed to create route route5 at: >>> To[jdbc:datasource] <<< in route: Route(route5)[[From[bean:sqlBean?method=generateSqlQuery('ci... because of Failed to resolve endpoint: jdbc://datasource due to: No bean could be found in the registry for: datasource of type: javax.sql.DataSource
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1830) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:136) ~[camel-spring-2.21.1.jar:2.21.1]
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:174) ~[camel-spring-2.21.1.jar:2.21.1]
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.17.RELEASE.jar:4.3.17.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.13.RELEASE.jar:1.5.13.RELEASE]
at com.example.SpringApacheDemoApplication.main(SpringApacheDemoApplication.java:15) [classes/:na]
Caused by: org.apache.camel.FailedToCreateRouteException: Failed to create route route5 at: >>> To[jdbc:datasource] <<< in route: Route(route5)[[From[bean:sqlBean?method=generateSqlQuery('ci... because of Failed to resolve endpoint: jdbc://datasource 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:1303) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1145) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3731) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3445) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:209) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3253) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3249) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3272) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3249) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3165) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.spring.SpringCamelContext.start(SpringCamelContext.java:133) ~[camel-spring-2.21.1.jar:2.21.1]
... 16 common frames omitted
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jdbc://datasource 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:758) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:219) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:115) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:121) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.SendDefinition.resolveEndpoint(SendDefinition.java:62) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.SendDefinition.createProcessor(SendDefinition.java:56) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.ProcessorDefinition.makeProcessorImpl(ProcessorDefinition.java:562) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:523) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:239) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1300) ~[camel-core-2.21.1.jar:2.21.1]
... 28 common frames omitted
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:189) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.component.jdbc.JdbcComponent.createEndpoint(JdbcComponent.java:52) ~[camel-jdbc-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:126) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:711) ~[camel-core-2.21.1.jar:2.21.1]
... 38 common frames omitted
Мой верблюжий маршрут:
from("bean:sqlBean?method=generateSqlQuery('tablename')")
.to("jdbc:datasource")
.process( new Processor () {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getOut().toString();
}});
РЕДАКТИРОВАТЬ: я добавил источник данных программно следующим образом:
@Bean
@Primary
public DataSource datasource() {
System.out.println("hihihi");
return DataSourceBuilder
.create()
.username("root")
.password("password")
.url("jdbc:mysql://localhost:3306/world?useSSL=false")
.driverClassName("com.mysql.jdbc.Driver")
.build();
}
Но теперь я сталкиваюсь с другой ошибкой:
Caused by: java.lang.UnsupportedOperationException: You cannot consume from a bean endpoint
at org.apache.camel.component.bean.BeanEndpoint.createConsumer(BeanEndpoint.java:75) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.EventDrivenConsumerRoute.addServices(EventDrivenConsumerRoute.java:69) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.DefaultRoute.onStartingServices(DefaultRoute.java:103) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.RouteService.doWarmUp(RouteService.java:172) ~[camel-core-2.21.1.jar:2.21.1]
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:145) ~[camel-core-2.21.1.jar:2.21.1]
... 28 common frames omitted