嗨,伙计们,我在 Karaf 4.3.6(最近的升级)中的数据源有一些问题,我希望有人能阐明我在这里做错了什么。
升级前
Karaf 有以下服务(org.osgi.service.jdbc.DataSourceFactory):
[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = com.microsoft.sqlserver.jdbc.SQLServerDriver
osgi.jdbc.driver.name = com.microsoft.sqlserver.mssql-jdbc-native
osgi.jdbc.driver.version = 6.2.2.jre8
service.bundleid = 46
service.id = 219
service.scope = singleton
Provided by :
Microsoft JDBC Driver for SQL Server (46)
[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = com.microsoft.sqlserver.jdbc.SQLServerDriver
osgi.jdbc.driver.name = Microsoft JDBC Driver for SQL Server
osgi.jdbc.driver.version = 7.4
service.bundleid = 47
service.id = 223
service.scope = singleton
Provided by :
Microsoft JDBC Driver for SQL Server (47)
[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = com.microsoft.sqlserver.jdbc.SQLServerDriver
osgi.jdbc.driver.name = mssql
service.bundleid = 157
service.id = 252
service.scope = singleton
Provided by :
OPS4J Pax JDBC MSSQL Driver Adapter (157)
Used by:
example-project(173)
OPS4J Pax JDBC Config (38)
我的项目蓝图包含以下内容:
<bean id="sqlComponent" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="exampleSQLServerDataSource"/>
</bean>
<service id="c1SQLDataSource" interface="javax.sql.DataSource" ref="exampleSQLServerDataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="exSQLDataSource"/>
</service-properties>
</service>
<bean id="exampleSQLServerDataSource" factory-ref="sqlServerDataSourceFactory" factory-method="createDataSource">
<argument>
<props>
<prop key="databaseName">${ex.db.dbname}</prop>
<prop key="user">${ex.db.user}</prop>
<prop key="password">${ex.db.password}</prop>
<prop key="portNumber">${ex.db.port}</prop>
<prop key="serverName">${ex.db.host}</prop>
</props>
</argument>
</bean>
<reference id="sqlServerDataSourceFactory" interface="org.osgi.service.jdbc.DataSourceFactory" filter="(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.name=mssql)"/>
使用此配置,我的项目在安装时运行良好/我可以将 camel-sql 组件与我的数据源一起使用。
升级后
对 karaf depensancys 的更改意味着 mssql 工厂不再可用(即使在启动 pax-jdbc-mssql 的功能时)
Karaf 有以下服务(org.osgi.service.jdbc.DataSourceFactory):
[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = com.microsoft.sqlserver.jdbc.SQLServerDriver
osgi.jdbc.driver.name = com.microsoft.sqlserver.mssql-jdbc-native
osgi.jdbc.driver.version = 6.2.2.jre8
service.bundleid = 54
service.id = 214
service.scope = singleton
Provided by :
Microsoft JDBC Driver for SQL Server (54)
[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = com.microsoft.sqlserver.jdbc.SQLServerDriver
osgi.jdbc.driver.name = Microsoft JDBC Driver for SQL Server
osgi.jdbc.driver.version = 9.2
service.bundleid = 55
service.id = 371
service.scope = singleton
Provided by :
Microsoft JDBC Driver for SQL Server (55)
[org.osgi.service.jdbc.DataSourceFactory]
-----------------------------------------
osgi.jdbc.driver.class = com.microsoft.sqlserver.jdbc.SQLServerDriver
osgi.jdbc.driver.name = Microsoft JDBC Driver for SQL Server
osgi.jdbc.driver.version = 9.4
service.bundleid = 282
service.id = 370
service.scope = singleton
Provided by :
Microsoft JDBC Driver for SQL Server (282)
我的项目蓝图包含以下内容:
我修改了我的 blueprint.xml 以使用 jdbc:ds-factories 中可用的其他连接之一,但我看到以下错误,抱怨缺少安装要求
<bean id="sqlComponent" class="org.apache.camel.component.sql.SqlComponent">
<property name="dataSource" ref="exampleSQLServerDataSource"/>
</bean>
<service id="c1SQLDataSource" interface="javax.sql.DataSource" ref="exampleSQLServerDataSource">
<service-properties>
<entry key="osgi.jndi.service.name" value="exSQLDataSource"/>
</service-properties>
</service>
<bean id="exampleSQLServerDataSource" factory-ref="sqlServerDataSourceFactory" factory-method="createDataSource">
<argument>
<props>
<prop key="databaseName">${ex.db.dbname}</prop>
<prop key="user">${ex.db.user}</prop>
<prop key="password">${ex.db.password}</prop>
<prop key="portNumber">${ex.db.port}</prop>
<prop key="serverName">${ex.db.host}</prop>
</props>
</argument>
</bean>
<reference id="sqlServerDataSourceFactory" interface="org.osgi.service.jdbc.DataSourceFactory" filter="(osgi.jdbc.driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver)(osgi.jdbc.driver.name=Microsoft JDBC Driver for SQL Server)(osgi.jdbc.driver.version=9.4)"/>
安装时看到此错误
karaf@root()> feature:install example-project
org.apache.felix.resolver.reason.ReasonException: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=example-project; type=karaf.feature; version="[0.1.4.SNAPSHOT,0.1.4.SNAPSHOT]"; filter:="(&(osgi.identity=example-project)(type=karaf.feature)(version>=0.1.4.SNAPSHOT)(version<=0.1.4.SNAPSHOT))" [caused by: Unable to resolve example-project/0.1.4.SNAPSHOT: missing requirement [example-project/0.1.4.SNAPSHOT] osgi.identity; osgi.identity=com.example.example.project; type=osgi.bundle; version="[0.1.4.SNAPSHOT,0.1.4.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve com.example.example.project/0.1.4.SNAPSHOT: missing requirement [com.example.example.project/0.1.4.SNAPSHOT] osgi.service; effective:=active; filter:="(&(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver)(osgi.jdbc.driver.name=Microsoft JDBC Driver for SQL Server)(osgi.jdbc.driver.version=9.4))"]]
at org.apache.felix.resolver.Candidates$MissingRequirementError.toException(Candidates.java:1341)
at org.apache.felix.resolver.ResolverImpl.doResolve(ResolverImpl.java:433)
at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:420)
at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:374)
at org.apache.karaf.features.internal.region.SubsystemResolver.resolve(SubsystemResolver.java:257)
at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:399)
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1069)
at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread$13(FeaturesServiceImpl.java:1004)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.felix.resolver.reason.ReasonException: Unable to resolve example-project/0.1.4.SNAPSHOT: missing requirement [example-project/0.1.4.SNAPSHOT] osgi.identity; osgi.identity=com.example.example.project; type=osgi.bundle; version="[0.1.4.SNAPSHOT,0.1.4.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve com.example.example.project/0.1.4.SNAPSHOT: missing requirement [com.example.example.project/0.1.4.SNAPSHOT] osgi.service; effective:=active; filter:="(&(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver)(osgi.jdbc.driver.name=Microsoft JDBC Driver for SQL Server)(osgi.jdbc.driver.version=9.4))"]
at org.apache.felix.resolver.Candidates$MissingRequirementError.toException(Candidates.java:1341)
... 12 more
Caused by: org.apache.felix.resolver.reason.ReasonException: Unable to resolve com.example.example.project/0.1.4.SNAPSHOT: missing requirement [com.example.example.project/0.1.4.SNAPSHOT] osgi.service; effective:=active; filter:="(&(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver)(osgi.jdbc.driver.name=Microsoft JDBC Driver for SQL Server)(osgi.jdbc.driver.version=9.4))"
at org.apache.felix.resolver.Candidates$MissingRequirementError.toException(Candidates.java:1341)
... 13 more
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=example-project; type=karaf.feature; version="[0.1.4.SNAPSHOT,0.1.4.SNAPSHOT]"; filter:="(&(osgi.identity=example-project)(type=karaf.feature)(version>=0.1.4.SNAPSHOT)(version<=0.1.4.SNAPSHOT))" [caused by: Unable to resolve example-project/0.1.4.SNAPSHOT: missing requirement [example-project/0.1.4.SNAPSHOT] osgi.identity; osgi.identity=com.example.example.project; type=osgi.bundle; version="[0.1.4.SNAPSHOT,0.1.4.SNAPSHOT]"; resolution:=mandatory [caused by: Unable to resolve com.example.example.project/0.1.4.SNAPSHOT: missing requirement [com.example.example.project/0.1.4.SNAPSHOT] osgi.service; effective:=active; filter:="(&(objectClass=org.osgi.service.jdbc.DataSourceFactory)(osgi.jdbc.driver.class=com.microsoft.sqlserver.jdbc.SQLServerDriver)(osgi.jdbc.driver.name=Microsoft JDBC Driver for SQL Server)(osgi.jdbc.driver.version=9.4))"]]
聚甲醛
我的 pom.xml 文件中的maven-bundle-plugin定义
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>
javax.jms;version="[2.0,3)",
org.xmlsoap.schemas.soap.envelope,
com.example.example.services.amqp.*,
*
</Import-Package>
</instructions>
</configuration>
</plugin>