virgo示例ClassNotFoundException

virgo示例ClassNotFoundException

本文介绍了osgi spring hibernate virgo示例ClassNotFoundException:org.hibernate.cfg.Configuration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图构建一个非常简单的应用程序,它将数据保存到数据库,作为osgi包(处女座下)运行。
当我尝试将jar上传到处女座低谷web界面,并得到下一个错误。

  [2011-02-13 23:19:26.317] start-signaling-4 org.eclipse.virgo.medic.eventlog.default DE0006E包'com.company.heartbeat'版本'0.1.0'的启动失败。 org.springframework.beans.factory.BeanCreationException:在URL [bundleentry://63.fwk1755147655/META-INF/spring/heartbeatcheck-context.xml]中定义名称为'beatDao'的Bean时创建错误:无法解析对bean的引用'sessionFactory 'while setting bean property'sessionFactory';嵌套异常是org.springframework.beans.factory.BeanCreationException:在URL [bundleentry://63.fwk1755147655/META-INF/spring/heartbeatcheck-context.xml]中定义的名称为'sessionFactory'的bean创建时出错:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[org.springframework.orm.hibernate3.LocalSessionFactoryBean]:构造函数抛出异常;嵌套异常是org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)处的org.springframework 
处的java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration
。 beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1305)
at org.springframework。 beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
处org.springframework org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
。 beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
在org.springframework.beans.fa ctory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans .factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans .factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.osgi.context .support.AbstractDelegatedExecutionApplicationContext.access $ 1600(AbstractDelegatedExecutionApplicationContext.java:69)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext $ 4.run(Abstract DelegatedExecutionApplicationContext.java:355)
at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(在org.eclipse.virgo.kernel上的
。 agent.dm.ContextPropagatingTaskExecutor $ 2.run(ContextPropagatingTaskExecutor.java:95)
at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908)
在java.lang.Thread.run(Thread.java:662)
导致:org.springframework.beans.factory.BeanCreationException:创建bean时出错与名称'会话工厂'在URL [bundleentry://63.fwk1755147655/META-INF/spring/heartbeatcheck-context.xml]中定义:bean的实例化失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[org.springframework.orm.hibernate3.LocalSessionFactoryBean]:构造函数抛出异常;嵌套异常是org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
在org.springframework上的java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration
。在org.springframework上
。org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
在org.springframework。
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework。 beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:290)
at org.springframework .beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFact org.springframework.beans.factory.support.AbstractBeanFactory.getBean上的ory.doGetBean(AbstractBeanFactory.java:287)
(org.springframework.beans.factory.support上的
)。 BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
...忽略20个常见框架
引起:org.springframework.beans.BeanInstantiationException:无法实例化bean类[org.springframework.orm.hibernate3。 LocalSessionFactoryBean]:构造函数抛出异常;嵌套异常是org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)上的org.springframework.beans.factory的
中的java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration
。 support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:938)
... 28个常用框架省略
导致:java.lang.NoClassDefFoundError:org / hibernate / cfg / Configuration $ b $在org.springframework.orm.hibernate3.LocalSessionFactoryBean。< init>(LocalSessionFactoryBean.java:189)
在太阳.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)$ b $ ja在ja va.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
... 30个常用框架省略
导致:org.eclipse.virgo.kernel.osgi.framework.ExtendedClassNotFoundException:org.hibernate.cfg.Configuration in KernelBundleClassLoader:[bundle = org.springframework.orm_3.0.0.RELEASE]
at org.eclipse .virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:139)$ b $在java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 36个常用框架省略
引起:java.lang.ClassNotFoundException:org.hibernate.cfg.Configuration
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
在org.ecli pse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:135)
... 37个常用框架省略

这是我的pom文件:

 <?xml version =1.0encoding =UTF-8?> 
< project xmlns =http://maven.apache.rg/POM/4.0.0xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">
< modelVersion> 4.0.0< / modelVersion>
< groupId> com.company< / groupId>
< artifactId> com.company.heartbeat< / artifactId>
< version> 0.1.0< / version>

<属性>
< bundle.name> HeartBeatCheck< /bundle.name>
< hibernate.version> 3.5.6-最终< /hibernate.version>
< org.springframework.version> 3.0.5.RELEASE< /org.springframework.version>
< / properties>

<依赖关系>
< dependency>
< groupId> org.osgi< / groupId>
< artifactId> org.osgi.core< / artifactId>
< version> 4.2.0< / version>
< /依赖关系>
< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< version> 5.1.14< / version>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-core< / artifactId>
< version> $ {org.springframework.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-orm< / artifactId>
< version> $ {org.springframework.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> $ {hibernate.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-annotations< / artifactId>
< version> $ {hibernate.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-hibernate3< / artifactId>
< version> 2.0.8< / version>
< /依赖关系>
< /依赖关系>

< build>
< plugins>
< plugin>
< groupId> org.apache.felix< / groupId>
< artifactId> maven-bundle-plugin< / artifactId>
< extensions> true< / extensions>
<配置>
<指令>
< Bundle-SymbolicName> $ {project.artifactId}< / Bundle-SymbolicName>
< Bundle-Name> $ {bundle.name}< / Bundle-Name>
<导出包装> $ {project.artifactId}< /导出包装>
< Bundle-Version> $ {pom.version}< / Bundle-Version>
<导出包裹> com.company.heartbeat。*< /导出包裹>
< / instructions>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / project>

我使用命令创建捆绑包:mvn clean install org.apache.felix:maven-bundle-plugin :bundle,我也把所有项目依赖关系的jar放到了server / repository / usr /目录下。

我刚开始学习osgi,错误。

解决方案

最后我解决了问题。我用来自springsource的osgi-ready替换了hibernate和mysql库。

 <依赖关系> 
< groupId> com.mysql.jdbc< / groupId>
< artifactId> com.springsource.com.mysql.jdbc< / artifactId>
< version> 5.1.6< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> com.springsource.org.hibernate< / artifactId>
< version> 3.3.2.GA< / version>
< /依赖关系>

此外,我将构建指令部分更改为(创建正确的清单):

 < instructions> 
< Bundle-SymbolicName> $ {project.artifactId}< / Bundle-SymbolicName>
< Bundle-Name> $ {bundle.name}< / Bundle-Name>
< Bundle-Version> $ {pom.version}< / Bundle-Version>
< Export-Package> $ {project.artifactId}。*< / Export-Package>
< Import-Bundle> com.springsource.org.hibernate< / Import-Bundle>
< / instructions>

并将bundle加载到virgo,并可以使用hibernate。


I'm trying to build very simple app that saving data to DB run as osgi bundle (under Virgo).When I try to upload jar to virgo trough webinterface, and get next error.

[2011-02-13 23:19:26.317] start-signalling-4           org.eclipse.virgo.medic.eventlog.default                         DE0006E Start failed for bundle 'com.company.heartbeat' version '0.1.0'. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'beatDao' defined in URL [bundleentry://63.fwk1755147655/META-INF/spring/heartbeatcheck-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [bundleentry://63.fwk1755147655/META-INF/spring/heartbeatcheck-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1305)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
    at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)
    at org.eclipse.virgo.kernel.agent.dm.ContextPropagatingTaskExecutor$2.run(ContextPropagatingTaskExecutor.java:95)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in URL [bundleentry://63.fwk1755147655/META-INF/spring/heartbeatcheck-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:946)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:890)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    ... 20 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:72)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:938)
    ... 28 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.<init>(LocalSessionFactoryBean.java:189)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
    ... 30 common frames omitted
Caused by: org.eclipse.virgo.kernel.osgi.framework.ExtendedClassNotFoundException: org.hibernate.cfg.Configuration in KernelBundleClassLoader: [bundle=org.springframework.orm_3.0.0.RELEASE]
    at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:139)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 36 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
    at org.eclipse.virgo.kernel.userregion.internal.equinox.KernelBundleClassLoader.loadClass(KernelBundleClassLoader.java:135)
    ... 37 common frames omitted

Here is my pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.rg/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company</groupId>
    <artifactId>com.company.heartbeat</artifactId>
    <version>0.1.0</version>

    <properties>
        <bundle.name>HeartBeatCheck</bundle.name>
        <hibernate.version>3.5.6-Final</hibernate.version>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.14</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-hibernate3</artifactId>
            <version>2.0.8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Name>${bundle.name}</Bundle-Name>
                        <Export-Package>${project.artifactId}</Export-Package>
                        <Bundle-Version>${pom.version}</Bundle-Version>
                        <Export-Package>com.company.heartbeat.*</Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I create bundle with command: "mvn clean install org.apache.felix:maven-bundle-plugin:bundle", also I put all project dependencies jars to server /repository/usr/ directory.

I'm start learning osgi a while ago, and most probably doing something wrong.

解决方案

Finally i resolved problem. I replaced hibernate and mysql libs with osgi-ready from springsource.

    <dependency>
        <groupId>com.mysql.jdbc</groupId>
        <artifactId>com.springsource.com.mysql.jdbc</artifactId>
        <version>5.1.6</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>com.springsource.org.hibernate</artifactId>
        <version>3.3.2.GA</version>
    </dependency>

Also I changed build instruction part to (so correct manifest is created):

  <instructions>
    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
    <Bundle-Name>${bundle.name}</Bundle-Name>
    <Bundle-Version>${pom.version}</Bundle-Version>
    <Export-Package>${project.artifactId}.*</Export-Package>
    <Import-Bundle>com.springsource.org.hibernate</Import-Bundle>
  </instructions>

And bundle loaded to virgo, and could use hibernate.

这篇关于osgi spring hibernate virgo示例ClassNotFoundException:org.hibernate.cfg.Configuration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:34