Jboss Fuse中的H2数据库

时间:2015-12-31 10:27:07

标签: h2 redhat esb jbossfuse

我正在尝试创建一个使用h2数据库的bundle。我正在使用felix maven插件。

我有felix配置就像

<Import-Package>*,org.h2.Driver,org.h2.*</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>

但我得到像这样的例外

org.osgi.service.blueprint.container.ComponentDefinitionException: Error setting property: PropertyDescriptor <name: driverClassName, getter: null, setter: [class org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(class java.lang.String)]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:941)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:907)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BeanRecipe.setProperties(BeanRecipe.java:888)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:820)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[21:org.apache.aries.blueprint.core:1.4.2]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_60]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:682)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:377)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[21:org.apache.aries.blueprint.core:1.4.2]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_60]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_60]
at org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)[21:org.apache.aries.blueprint.core:1.4.2]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_60]
at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_60]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)[:1.8.0_60]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)[:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_60]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_60]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_60]

Caused by: java.lang.IllegalStateException: Could not load JDBC driver class [org.h2.Driver]
at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:150)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_60]
at org.apache.aries.blueprint.utils.ReflectionUtils$MethodPropertyDescriptor.internalSet(ReflectionUtils.java:628)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.utils.ReflectionUtils$PropertyDescriptor.set(ReflectionUtils.java:378)[21:org.apache.aries.blueprint.core:1.4.2]
at org.apache.aries.blueprint.container.BeanRecipe.setProperty(BeanRecipe.java:939)[21:org.apache.aries.blueprint.core:1.4.2]
... 23 more

Caused by: java.lang.ClassNotFoundException: org.h2.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)[:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)[:1.8.0_60]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)[:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_60]
at java.lang.Class.forName0(Native Method)[:1.8.0_60]
at java.lang.Class.forName(Class.java:348)[:1.8.0_60]
at org.springframework.jdbc.datasource.DriverManagerDataSource.setDriverClassName(DriverManagerDataSource.java:147)
... 30 more

但是我对mysql数据库做了同样的事情并且工作正常。但我想在我的捆绑中使用h2,我也面临着与hsql数据库相同的问题。看起来我错过了什么,请帮助我。

1 个答案:

答案 0 :(得分:1)

您的异常与felix插件无关,依赖jars和数据源的必要属性不存在。将属性添加到您的数据源,如下所示。

    <property name="url" value="jdbc:h2:<url>"/>
    <property name="username" value="user"/>
    <property name="password" value=""/>
    <property name="driverClassName" value="org.h2.Driver"/>

并添加依赖项

  <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>your version</version>
    </dependency>