关于SPRING 和 HIBERNATE整合时候出的问题,求解答(线上等,初学者)

问题描述

错误信息:SpringTestcn.itcast.oa.test.SpringTesttestSessionFactory(cn.itcast.oa.test.SpringTest)org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[applicationContext.xml]:Instantiationofbeanfailed;nestedexceptionisorg.springframework.beans.BeanInstantiationException:Couldnotinstantiatebeanclass[org.springframework.orm.hibernate3.LocalSessionFactoryBean]:Constructorthrewexception;nestedexceptionisjava.lang.NoClassDefFoundError:org/slf4j/LoggerFactory我写的测试文件packagecn.itcast.oa.test;importorg.hibernate.SessionFactory;importorg.junit.Test;importorg.springframework.context.ApplicationContext;importorg.springframework.context.support.ClassPathXmlApplicationContext;publicclassSpringTest{//测试SessionFactory@TestpublicvoidtestSessionFactory()throwsException{ApplicationContextac=newClassPathXmlApplicationContext("applicationContext.xml");SessionFactorysessionFactory=(SessionFactory)ac.getBean("sessionFactory");System.out.println("--->"+sessionFactory);}}然后我的applicationContext.xml<?xmlversion="1.0"encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><!--自动扫描雨装配bean--><context:component-scanbase-package="cn.itcast.oa"></context:component-scan><!--加载外部的配置文件--><context:property-placeholderlocation="classpath:jdbc.properties"/><!--配置SessionFactory--><beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!--指定主配置文件的路径--><propertyname="configLocation"value="hibernate.cfg.xml"></property><!--配置数据库连接池c3p0--><propertyname="dataSource"><beanclass="com.mchange.v2.c3p0.ComboPooledDataSource"></bean></property><!--数据库连接信息--><propertyname="jdbcUrl"value="${jdbcUrl}"></property><propertyname="driverClass"value="${driverClass}"></property><propertyname="user"value="${user}"></property><propertyname="password"value="${password}"></property><!--其他信息--><!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default:3--><propertyname="initialPoolSize"value="3"></property><!--连接池中保留的最小连接数。Default:3--><propertyname="minPoolSize"value="3"></property><!--连接池中保留的最大连接数。Default:15--><propertyname="maxPoolSize"value="5"></property><!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default:3--><propertyname="acquireIncrement"value="3"></property><!--控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default:0--><propertyname="maxStatements"value="8"></property><!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default:0--><propertyname="maxStatementsPerConnection"value="5"></property><!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default:0--><propertyname="maxIdleTime"value="1800"></property></bean><!--配置声明式事物管理,采用基于注解的方式--></beans>

解决方案

解决方案二:
applicationContext.xml配置文件错了
解决方案三:
引用1楼wpq139234的回复:

applicationContext.xml配置文件错了

那块错了,麻烦说细点。。。谢谢
解决方案四:
<!--配置SessionFactory--><beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!--指定主配置文件的路径--><propertyname="configLocation"value="hibernate.cfg.xml"></property><!--配置数据库连接池c3p0--><propertyname="dataSource"><beanclass="com.mchange.v2.c3p0.ComboPooledDataSource"></bean></property><!--数据库连接信息--><propertyname="jdbcUrl"value="${jdbcUrl}"></property><propertyname="driverClass"value="${driverClass}"></property><propertyname="user"value="${user}"></property><propertyname="password"value="${password}"></property><!--其他信息--><!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default:3--><propertyname="initialPoolSize"value="3"></property><!--连接池中保留的最小连接数。Default:3--><propertyname="minPoolSize"value="3"></property><!--连接池中保留的最大连接数。Default:15--><propertyname="maxPoolSize"value="5"></property><!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default:3--><propertyname="acquireIncrement"value="3"></property><!--控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default:0--><propertyname="maxStatements"value="8"></property><!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default:0--><propertyname="maxStatementsPerConnection"value="5"></property><!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default:0--><propertyname="maxIdleTime"value="1800"></property></bean><!--配置声明式事物管理,采用基于注解的方式-->你这一块没有提示错误么?我的写法:希望能帮你<!--会话配置--><beanid="sessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><propertyname="dataSource"ref="dataSource"/><!--引用数据源--><propertyname="hibernateProperties"><props><propkey="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop><propkey="hibernate.show_sql">true</prop><propkey="hibernate.format_sql">false</prop><propkey="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop><propkey="hibernate.cache.use_query_cache">false</prop></props></property></bean><!--配置数据源--><beanid="dataSource"class="org.logicalcobwebs.proxool.ProxoolDataSource"><propertyname="driver"value="${jdbc.driverClassName}"/><propertyname="driverUrl"value="${jdbc.url}"/><propertyname="user"value="${jdbc.username}"/><propertyname="password"value="${jdbc.password}"/><propertyname="maximumConnectionCount"value="${proxool.maxConnCount}"/><propertyname="minimumConnectionCount"value="${proxool.minConnCount}"/><propertyname="statistics"value="${proxool.statistics}"/><propertyname="simultaneousBuildThrottle"value="${proxool.simultaneousBuildThrottle}"/><propertyname="trace"value="${proxool.trace}"/><propertyname="verbose"value="${proxool.verbose}"/></bean>
解决方案五:
<!--指定主配置文件的路径--><propertyname="configLocation"value="hibernate.cfg.xml"></property>上面这个而错了,这个应该写成<!--指定主配置文件的路径--><propertyname="configLocation"value="classpath:hibernate.cfg.xml"></property>
解决方案六:
你看看这个这里spring和hibernate已经集成好了的
解决方案七:
引用4楼software_gemeng的回复:

<!--指定主配置文件的路径--><propertyname="configLocation"value="hibernate.cfg.xml"></property>上面这个而错了,这个应该写成<!--指定主配置文件的路径--><propertyname="configLocation"value="classpath:hibernate.cfg.xml"></property>

不是这个原因,我试了
解决方案八:
Quote: 引用3楼wpq139234的回复:

虽然还是不成,但是谢谢拉
解决方案九:
引用5楼qq467339640的回复:
你看看这个这里spring和hibernate已经集成好了的

帅哥啊。。。人家是初学者。。。现在刚弄那个STRUTS+SPRING+HIBERNATE。。。。
解决方案十:
你看下是不是这里的问题。我的是这样的!
解决方案十一:
引用9楼pk877841241的回复:

你看下是不是这里的问题。我的是这样的!

换成这个。。。报错信息还是一样的。。。
解决方案十二:
org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'sessionFactory'definedinclasspathresource[applicationContext.xml]:Errorsettingpropertyvalues;nestedexceptionisorg.springframework.beans.NotWritablePropertyException:Invalidproperty'jdbcUrl'ofbeanclass[org.springframework.orm.hibernate3.LocalSessionFactoryBean]:Beanproperty'jdbcUrl'isnotwritableorhasaninvalidsettermethod.Doestheparametertypeofthesettermatchthereturntypeofthegetter?。。到底那里错了啊
解决方案十三:
java.lang.NoClassDefFoundError:org/slf4j/LoggerFactory没有slf4.jar
解决方案十四:
可能是楼上的那个原因
解决方案十五:
缺jar包啊

时间: 2024-09-02 23:22:03

关于SPRING 和 HIBERNATE整合时候出的问题,求解答(线上等,初学者)的相关文章

spring和hibernate整合出错,请大神帮忙解决,谢谢

问题描述 spring和hibernate整合出错,请大神帮忙解决,谢谢 <!-- Hibernate和spring整合的配置 配置SessionFactory --> <!-- 指定hibernate的配置文件位置 --> <!-- 配置c3p0数据库连接池 --> <!--通过反射设置set方法--> <!-- 数据连接信息 --> <!-- 其他配置 --> <!-- 初始化时获取三个连接,取值应在minPoolSize与

spring和hibernate整合

问题描述 spring和hibernate整合 class="org.apache.commons.dbcp.BasicDataSource"> value="com.mysql.jdbc.Driver"> class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource">

SSH整合学习笔记之spring与hibernate整合(二)--C3P0

SSH整合学习笔记 现在将之前的spring与hibernate整合修改一下,使用C3P0数据库连接池.基本的配置没有改变,只是增加了一个jdbc.properties文件和修改了applicationContext.xml和hibernate.cfg.xml文件的相关配置. jdbc.properties jdbcUrl= jdbc:mysql:///spring2hibernate driverClass = com.mysql.jdbc.Driver username = root pas

hibernate4-求助大神,spring.springMvc.hibernate整合。并且全是注解

问题描述 求助大神,spring.springMvc.hibernate整合.并且全是注解 实在找不到教程,望能提供和完整的教程,视频最好 解决方案 给你了你就跑了不采纳怎么办?所以如果需要教程,请先采纳下姐姐的回答,姐姐这就给你. 解决方案二: 慕课网上找找,还有csdn学院里面找找,传智播客的视频教程 找找总有的.现在网络资源这么丰富,勤快耐心点,学习资源还是一大堆的.祝好! 解决方案三: 这个从网上搜吧.去git 里面找个下载. 解决方案四: http://v.youku.com/v_sh

spring-在Spring MVC,Spring,Hibernate整合项目中,jetty无法启动?

问题描述 在Spring MVC,Spring,Hibernate整合项目中,jetty无法启动? jetty启动时错误如下,显示servlet类找不到? 2016-03-22 21:04:50.227:WARN:oejuc.AbstractLifeCycle:FAILED o.e.j.w.WebAppContext{/,file:/F:/Project/FireGoBacker/Client/webapp/},F:ProjectFireGoBackerClientwebapp: java.la

我用spring mvc+mybatis整合为什么出这个错误,是不是路径错误?我是新手,请大神指教

问题描述 我用spring mvc+mybatis整合为什么出这个错误,是不是路径错误?我是新手,请大神指教 org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: file [D:JAVANewWorkspace.metadata.pluginsorg.eclipse.wst.server.coretmp0wtpwebappsstudent

hibernate-这个应该是Hibernate,的知识吧,求解答

问题描述 这个应该是Hibernate,的知识吧,求解答 求详细解释每一个重点,每一个细节,谢谢啦,大神们 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

jboss配置出问题,求解答

问题描述 jboss配置出问题,求解答 eclipse4.4.2配置jboss时有些不能安装,只能安装一部分

android studio-Android studio 大部分系统方法报红 让我setup jdk 代码提示也出不来 求解答

问题描述 Android studio 大部分系统方法报红 让我setup jdk 代码提示也出不来 求解答 Android studio 大部分系统方法报红 让我setup jdk 代码提示也出不来 求解答 解决方案 前段时间还好好的 今天弄个程序弄一般突然这样了 求大大解答 解决方案二: 我今天也碰到了同样的问题,希望能帮助到你,其实你只要更新你的SDK就可以了,或者你点击右下角的eventlog中报错的信息中的报错信息 系统会判断你应该升级或者安装缺少的组件,你点击就行了.我就是这样解决问