我已经使用pax-jdbc-config和以下URL
创建了数据源服务https://ops4j1.jira.com/wiki/spaces/PAXJDBC/pages/61767710/Create+DataSource+from+config
现在可以使用数据源服务
karaf@root()> service:list javax.sql.DataSource
[javax.sql.DataSource]
----------------------
dataSourceName = MySqlDS
felix.fileinstall.filename = file:/C:/Apache/apache-karaf-4.2.0/etc/org.ops4j.datasource-MySqlDS.cfg
osgi.jdbc.driver.class = com.mysql.jdbc.Driver
osgi.jdbc.driver.name = mysql
osgi.jndi.service.name = java:/MySqlDS
password = root
service.bundleid = 102
service.factoryPid = org.ops4j.datasource
service.id = 147
service.pid = org.ops4j.datasource.eaeb33be-1dcc-4f56-b9f3-37f5185ad761
service.scope = singleton
url = jdbc:mysql://localhost:3306/test
user = root
Provided by :
OPS4J Pax JDBC Config (102)
但在运行我的camel-scr路线时,我遇到了错误
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: MySqlDS of type: javax.sql.DataSource
at org.apache.camel.util.CamelContextHelper.mandatoryLookupAndConvert(CamelContextHelper.java:201) ~[76:org.apache.camel.camel-core:2.19.5]
at org.apache.camel.util.EndpointHelper.resolveReferenceParameter(EndpointHelper.java:326) ~[76:org.apache.camel.camel-core:2.19.5]
at org.apache.camel.util.EndpointHelper.resolveReferenceParameter(EndpointHelper.java:308) ~[76:org.apache.camel.camel-core:2.19.5]
at org.apache.camel.impl.DefaultComponent.resolveAndRemoveReferenceParameter(DefaultComponent.java:415) ~[76:org.apache.camel.camel-core:2.19.5]
at org.apache.camel.impl.DefaultComponent.resolveAndRemoveReferenceParameter(DefaultComponent.java:394) ~[76:org.apache.camel.camel-core:2.19.5]
at org.apache.camel.component.sql.SqlComponent.createEndpoint(SqlComponent.java:62) ~[131:org.apache.camel.camel-sql:2.19.5]
at org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:116) ~[76:org.apache.camel.camel-core:2.19.5]
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:676) ~[76:org.apache.camel.camel-core:2.19.5]
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80) ~[76:org.apache.camel.camel-core:2.19.5]
Camel SCR Runner片段:
protected void setupCamelContext(BundleContext bundleContext, String camelContextId)throws Exception{
super.setupCamelContext(bundleContext, camelContextId);
getContext().setUseMDCLogging(true);
getContext().setUseBreadcrumb(true);
SqlComponent sql = new SqlComponent();
getContext().addComponent("sql", sql);
}
骆驼路线
public void configure() throws Exception {
// Add a bean to Camel context registry
AbstractCamelRunner.getRegistry(getContext(), SimpleRegistry.class).put("testString", "this is a test");
from("{{from}}")
.to("sql:select * from table?dataSource=#MySqlDS&outputType=StreamList&outputClass=org.apache.camel.component.sql.ProjectModel")
.to("log:stream")
.split(body()).streaming()
.to("log:row")
.to("mock:result")
.end();
}
因为我正在使用#MySqlDS,它假设从服务注册表中获取它,或者我必须添加setupcamelcontext以及如何使用?
答案 0 :(得分:0)
使用dataSource =选项时,Camel SQL Component需要引用。
MySqlDS是osgi.jndi.service.name而不是引用ID