关于spring整合hibernate的问题

来源:百度知道 编辑:UC知道 时间:2024/06/08 18:38:21
请问org.springframework.orm.hibernate3.LocalSessionFactoryBean类是在哪个包下面,我的项目抱这个错:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sf' defined in file [D:\Tomcat\apache-tomcat-6.0.18\webapps\ssh\WEB-INF\classes\application-transaction.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: ServletContext resource [/dao/hibernate.cfg.xml] cannot be resolved to URL because it does not exist
Caused by: java.io.FileNotFoundException: ServletContext resource [/dao/hibernate.cfg.xml] cannot be resolved to URL because it does not exist
at org.springframework.web.context.support.ServletContextResource.getURL(ServletContextResource.java:112)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessio

spring.jar这个jar包下有这个类。
但是你的错误不是找不到这个类啊
而是这个类中抛出的错误。
错误建立个叫‘sf’的bean,在D盘的..xml文件中。因为一个文件没有被找到!
[/dao/hibernate.cfg.xml] 不能被解析因为它不存在。

所以检查下配置这个文件的路径对不对!

找一下这个包:spring-hibernate3.jar

还要要保证:commons-dbcp.jar
commons-collections-x.x.x.jar
再你的目录下。这两个是保证dataSource配置的~

你把它们下载下来放到你的lib目录~
然后类似那么配置就可以了。

<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/test"/>
<property name="username" value="root"/>
<property name="password" value="ykzhen"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">