English 中文(简体)
Hibernate + Spring - xmlography not found
原标题:Hibernate + Spring - xml mapping not found

我的简单应用结构如下:

  • ProjFolder
  • |-----src
  • |----------packagename
  • |---------------{sourcefiles}
  • |----------META-INF
  • |---------------{beans.xml}
  • |---------------{hibernate.cfg.xml}
  • |---------------{EntityMapping.hbm.xml}

这里是豆类的一部分。 Spring config文档:

<bean id="propertyConfigurer"  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location" value="classpath:./META-INF/jdbc.properties" />
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:./META-INF/hibernate.cfg.xml" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
        </props>
    </property>

    <property name="mappingResources">
<list>
      <value>classpath:./META-INF/EntityMapping.hbm.xml</value>
</list>
 </property>
</bean>

<tx:annotation-driven transaction-manager="txManager" />

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

一开始我的单位测试时,会发现以下例外情况:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name wrapperClass defined in class path resource [META-INF/beans.xml]: Cannot resolve reference to bean wrapperClassField while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name xmlBooksource defined in class path resource [META-INF/beans.xml]: Cannot resolve reference to bean sessionFactory while setting bean property sessionFactory ; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name sessionFactory defined in class path resource [META-INF/beans.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [classpath:/META-INF/EntityMapping.hbm.xml] cannot be opened because it does not exist

在一类情况下,也出现了同样的例外。

<property name="mappingResources">
<list>
      <value>EntityMapping.hbm.xml</value>
</list>
 </property>

为什么春天能够找到这一档案,以及我必须如何填补其所在地,使这一法典发挥作用?

提前感谢。

最佳回答
问题回答

I m not sure the error message is consistent with the beans.xml content you posted. In the error you have

[classpath:/META-INF/EntityMapping.hbm.xml]

不适用

 classpath:./META-INF/EntityMapping.hbm.xml

在错误一开始即通知失踪人员。

二级豆类组合可能会产生一种不同的错误信息:

[classpath:EntityMapping.hbm.xml]

这将在你汇编的申请(杰尔、战争、爆炸、你拥有的东西)中查找档案。

I have successfully configure Hibernate 4 with Spring 3.1. My applicationContext.xml file is inside web-inf folder and has the following hibernate cofiguration:

<!-- Session Factory Declaration -->
 <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  <property name="dataSource" ref="DataSource" />
  <!--  
  <property name="annotatedClasses">
   <list>
    <value>iltaf.models.Levels</value>
   </list>
  </property>
  -->

    <property name="mappingLocations" value="classpath:iltaf/models/*.hbm.xml" />


    <property name="configLocation">
        <value>classpath:hibernate.cfg.xml</value>
    </property>

  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
   </props>
  </property>
 </bean>

 <!-- Enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="txManager"/>

 <!-- Transaction Manager is defined -->
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
       <property name="sessionFactory" ref="SessionFactory"/>
    </bean>

</beans>

并且,在我的弧内,我有单独的猎物。 我正在使用Eclipse Juno Java EE版本。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签