浏览 5804 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2005-03-16
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean"> <property name="dataSource"><ref local="dataSource"/></property> <property name="mappingResources"> <list> <value>Employee.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">net.sf.hibernate.dialect.Oracle9Dialect</prop> </props> </property> </bean> <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --> <bean id="transactionManager" class="org.springframework.orm.hibernate.HibernateTransactionManager"> <property name="sessionFactory"><ref local="sessionFactory"/></property> </bean> <!-- RoleDAO: Hibernate implementation --> <bean id="empDAO" class="first.app.dao.hibernate.OrclHibernateEmpDAO"> <property name="sessionFactory"><ref local="sessionFactory"/></property> </bean> <!-- Add new DAOs here --> <!--dataSource location--> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"><value>oracle.jdbc.driver.OracleDriver</value></property> <property name="url"><value>jdbc:oracle:thin:@192.168.2.200:1521:qydb</value></property> <property name="username"><value>jbridge</value></property> <property name="password"><value>password</value></property> <property name="validationQuery"><value>SELECT 1 from dual</value></property> <property name="maxActive"><value>20</value></property> <property name="maxIdle"><value>20</value></property> <property name="maxWait"><value>-1</value></property> <property name="defaultAutoCommit"><value>false</value></property> <property name="defaultReadOnly"><value>false</value></property> </bean> </beans> 当我进行junit的时候总是抛 org.springframework.beans.FatalBeanException: Can't resolve reference to bean 'sessionFactory' while setting property 'sessionFactory' on bean 'transactionManager'; nested exception is: org.springframework.beans.FatalBeanException: afterPropertiesSet() on bean with name 'sessionFactory' threw exception; nested exception is: net.sf.hibernate.MappingException: Error reading resource: config/Employee.hbm.xml 我知道,可能是我Employee.hbm.xml映射文件的路径写的不对,于是我就加了包/config/Employee.hbm.xml,还是不对 我建的包是这样的 src ----config(放xml文件,包括Employee.hbm.xml) ----first --------dao --------domain -----------------entity(对应Employee.hbm.xml的类) 找了2天,也没能解决这个问题,只好来这里问大家。 谢谢,大家能不我解答一下 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2005-03-16
config/Employee.hbm.xml
这样就可以了 |
|
返回顶楼 | |
发表时间:2005-03-16
这个方法我也实验过了,结果还是
org.springframework.beans.FatalBeanException: Can't resolve reference to bean 'sessionFactory' while setting property 'sessionFactory' on bean 'transactionManager'; nested exception is: org.springframework.beans.FatalBeanException: afterPropertiesSet() on bean with name 'sessionFactory' threw exception; nested exception is: net.sf.hibernate.MappingException: Error reading resource: config/Employee.hbm.xml |
|
返回顶楼 | |
发表时间:2005-03-17
我跟进源码,发现在Hibernate中
public Configuration addResource(String path, ClassLoader classLoader) throws MappingException { log.info("Mapping resource: " + path); InputStream rsrc = classLoader.getResourceAsStream(path); if (rsrc==null) throw new MappingException("Resource: " + path + " not found"); try { return addInputStream(rsrc); } catch (MappingException me) { throw new MappingException("Error reading resource: " + path, me); } } 这个方法抛出异常 就是这句InputStream rsrc = classLoader.getResourceAsStream(path); 这时path路径是正确的,我不明白是为什么 |
|
返回顶楼 | |
发表时间:2005-03-21
问题解决了,
是因为在jbuiler编译的时候,我没有把工程--〉properties--〉build--〉resource--〉xml拷贝这个选项给选中 |
|
返回顶楼 | |