日期:2014-05-19  浏览次数:20733 次

Spring与Hibernate整合时/hibernate.cfg.xml not found
我的配置文件都是自动生成的,但是运行的时候报错了
这是applicationContext.xml
XML code
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver">
        </property>
        <property name="url"
            value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf8">
        </property>
        <property name="username" value="root"></property>
        <property name="password" value="123456"></property>
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/jiaoyou/entity/Basic.hbm.xml</value>
                <value>com/jiaoyou/entity/Choose.hbm.xml</value>
                <value>com/jiaoyou/entity/Note.hbm.xml</value>
                <value>com/jiaoyou/entity/Message.hbm.xml</value>
                <value>com/jiaoyou/entity/User.hbm.xml</value>
                <value>com/jiaoyou/entity/Mail.hbm.xml</value>
                <value>com/jiaoyou/entity/Picture.hbm.xml</value>
            </list>
        </property>
    </bean>
</beans>


保错:
Java code

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
%%%% Error Creating SessionFactory %%%%
org.hibernate.HibernateException: /hibernate.cfg.xml not found
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1402)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1424)
    at com.jiaoyou.factory.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:30)
    at com.jiaoyou.dao.impl.UserDAOImpl.getUserByUsername(UserDAOImpl.java:37)
    at com.jiaoyou.dao.impl.UserDAOImpl.main(UserDAOImpl.java:58)
%%%% Error Creating SessionFactory %%%%
org.hibernate.HibernateException: /hibernate.cfg.xml not found
    at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
    at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1402)
    at org.hibernate.cfg.Co