首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

Spring与Hibernate整合时/hibernate.cfg.xml not found解决方法

2012-04-28 
Spring与Hibernate整合时/hibernate.cfg.xml not found我的配置文件都是自动生成的,但是运行的时候报错了

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.Configuration.configure(Configuration.java:1424)    at com.jiaoyou.factory.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:69)    at com.jiaoyou.factory.HibernateSessionFactory.getSession(HibernateSessionFactory.java:53)    at com.jiaoyou.dao.impl.UserDAOImpl.getUserByUsername(UserDAOImpl.java:37)    at com.jiaoyou.dao.impl.UserDAOImpl.main(UserDAOImpl.java:58)Exception in thread "main" java.lang.NullPointerException    at com.jiaoyou.dao.impl.UserDAOImpl.getUserByUsername(UserDAOImpl.java:39)    at com.jiaoyou.dao.impl.UserDAOImpl.main(UserDAOImpl.java:58) 



不知道那里错了????

[解决办法]
/hibernate.cfg.xml not found

文件没有找到
XML code
applicationContext.xml(/WEB-INF/applicationContext.xml)<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"><beans>   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">     <property name="driverClassName" value="org.gjt.mm.mysql.Driver" />     <property name="url" value="jdbc:mysql://localhost:3306/stud"/>     <property name="username" value="root" />     <property name="password" value="root" />   </bean>    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">     <property name="dataSource" ref="dataSource" />     <property name="hibernateProperties">      <props>       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>       <prop key="hibernate.show_sql">true</prop>      </props>     </property>     <property name="mappingResources">      <list>       <value>com/ex/model/Employee.hbm.xml</value>      </list>     </property>   </bean>  <bean id="employeeDao" class="com.ex.dao.impl.EmployeeDaoImpl">  <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="employeeManager" class="com.ex.service.impl.EmployeeManagerImpl">  <property name="employeeDao" ref="employeeDao" /> </bean>  <bean id="addBean" class="com.ex.action.EmployeeAction" scope="prototype">  <property name="employeeManager" ref="employeeManager" /> </bean> <bean id="editBean" class="com.ex.action.EmployeeAction" scope="prototype">  <property name="employeeManager" ref="employeeManager" /> </bean>  <bean id="updateBean" class="com.ex.action.EmployeeAction" scope="prototype">  <property name="employeeManager" ref="employeeManager" /> </bean>   <bean id="deleteBean" class="com.ex.action.EmployeeAction" scope="prototype">  <property name="employeeManager" ref="employeeManager" /> </bean>  <bean id="saveOrUpdateBean" class="com.ex.action.EmployeeAction" scope="prototype">  <property name="employeeManager" ref="employeeManager" /> </bean>  <bean id="listBean" class="com.ex.action.EmployeeAction" scope="prototype">   <property name="employeeManager" ref="employeeManager" /> </bean>  <bean id="loginBean" class="com.ex.action.EmployeeAction" scope="prototype">  <property name="employeeManager" ref="employeeManager" /> </bean>  </beans>3、web.xml<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>ssh_demo4</display-name> <welcome-file-list>  <welcome-file>index.jsp</welcome-file> </welcome-file-list> <filter>  <filter-name>struts2</filter-name>  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping>  <filter-name>struts2</filter-name>  <url-pattern>/*</url-pattern> </filter-mapping> <listener>  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>  </web-app> 


[解决办法]
<property name="url"
value="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf8">
</property>
你的url连接是这个,数据库是哪个啊
[解决办法]
找不到main方法,那就在main里面看看呗

热点排行