正确的Spring和Hibernate版本以及所需的依赖项...依赖项导致的异常 [英] Correct version of Spring and Hibernate and required dependencies...Exception due to dependencies

查看:75
本文介绍了正确的Spring和Hibernate版本以及所需的依赖项...依赖项导致的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于三天以来,我一直在尝试运行Spring-Hibernate程序.由于hibernate2和hibernate3之间的版本差异,我很难找到所涉及的依赖项. 最终,我能够使用以下一组依赖项来运行程序

Since three days i am trying to get my Spring-Hibernate programs run. i had really tough time finding the involved dependencies due to version difference between hibernate2 and hibernate3. Finally i was able to run program with following set of dependencies

  • cglib-nodep-2.1_3.jar
  • commons-collections.jar
  • commons-dbcp.jar
  • commons-pool.jar
  • commons-logging.jar
  • dom4j-1.4.jar
  • ehcache-1.6.0-beta1.jar
  • hibernate-3.1.3.jar
  • hsqldb.jar
  • jta.jar log4j-1.2.9.jar
  • mysql-connector-java-5.0.8-bin.jar
  • org.springframework.orm-3.1.0.M1.jar
  • org.springframework.transaction-3.1.0.M1.jar
  • spring-2.5.6.jar
  • spring-beans-2.0.4.jar
  • cglib-nodep-2.1_3.jar
  • commons-collections.jar
  • commons-dbcp.jar
  • commons-pool.jar
  • commons-logging.jar
  • dom4j-1.4.jar
  • ehcache-1.6.0-beta1.jar
  • hibernate-3.1.3.jar
  • hsqldb.jar
  • jta.jar log4j-1.2.9.jar
  • mysql-connector-java-5.0.8-bin.jar
  • org.springframework.orm-3.1.0.M1.jar
  • org.springframework.transaction-3.1.0.M1.jar
  • spring-2.5.6.jar
  • spring-beans-2.0.4.jar

经过两天的努力,当我能够管理上述依赖关系时,我尝试构建类似的程序,但是它抛出以下错误.我尝试在线寻求解决方案,但发现该解决方案的版本不正确.休眠状态...任何人都可以告诉我正确的异常原因以及Spring和休眠状态的正确版本

now after two days of efforts when i was able to manage the above mentioned dependencies i tried building similar program but it is throwing following error.I tried online for solution but the solution which i found there is not correct version of spring and hibernate ...Can any one tell me correct cause of exception and also correct version of the Spring and hibernate

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRecordDAO' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateTemplate' defined in class path resource [applicationContext.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 class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)


我还添加了我的应用程序context.xml


I am also adding my application context.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/subhash"/>
        <property name="username" value="root"/>
        <property name="password" value=""></property>
    </bean>


    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource"><ref local="dataSource"/></property>
        <property name="mappingResources">
            <list>
                <value>MyRecord.hbm.xml</value>
            </list>
         </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                <prop key="show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>

    </bean>

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
    <bean id="myRecordDAO" class="com.shoesobjects.MyRecordDAOHibernateWithSpring">
        <property name="hibernateTemplate"><ref local="hibernateTemplate"/></property>
    </bean>
</beans>

推荐答案

a)

注意
从Spring 3.0开始,Spring需要 Hibernate 3.2或更高版本.

Note
As of Spring 3.0, Spring requires Hibernate 3.2 or later.

来源:

b)

  • org.springframework.orm- 3.1.0.M1 .jar
  • org.springframework.transaction- 3.1.0.M1 .jar
  • spring- 2.5.6 .jar
  • spring-beans- 2.0.4 .jar
  • org.springframework.orm-3.1.0.M1.jar
  • org.springframework.transaction-3.1.0.M1.jar
  • spring-2.5.6.jar
  • spring-beans-2.0.4.jar

您真的认为将当前的预发行版本(3.1.x)与较旧的版本(2.0.4在2007年发行)混合是一个好主意吗?

Do you really think mixing current pre-release versions (3.1.x) with ancient versions (2.0.4 was released in 2007) is a good idea?

matt所说:使用像Maven这样的依赖管理系统,您要处理的是jar hell.这是一篇有关从Maven引用Spring 3.x工件的文章:

As matt says: use a dependency managements system like Maven, what you are dealing with is jar hell. Here's an article about referencing Spring 3.x artifacts from maven:

获得Spring 3与神器 Maven

Obtaining Spring 3 Artifacts with Maven

这篇关于正确的Spring和Hibernate版本以及所需的依赖项...依赖项导致的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆