2012-05-30 155 views
0

我正在尝试将Spring 3与Spring 3.1.0集成。问题在于应用程序无法找到在hibernate.cfg.xml文件中声明的映射文件。最初,hibernate配置具有数据源配置,hibernate属性和映射hbm.xml文件。 高级hibernate.cfg.xml文件存在于src文件夹中。这是主文件的外观:将Spring配置文件导入Spring应用程序上下文

<hibernate-configuration> 
    <session-factory> 
     <!-- Mappings --> 
     <mapping resource="com/test/class1.hbm.xml"/> 
     <mapping resource="/class2.hbm.xml"/> 
     <mapping resource="com/test/class3.hbm.xml"/> 
     <mapping resource="com/test/class4.hbm.xml"/> 
     <mapping resource="com/test/class5.hbm.xml"/> 

Spring配置是:

<bean id="sessionFactoryEditSolution" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="data1"/> 
     <property name="mappingResources"> 
      <list> 
       <value>/master.hibernate.cfg.xml</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> 
       <prop key="hibernate.cache.use_second_level_cache">true</prop> 

      </props> 
     </property> 
    </bean> 

回答

1

你可以自由路径的开头斜杠,所以你正在寻找根吧。这几乎肯定是不正确的。

<value>/master.hibernate.cfg.xml</value> 

我通常指定我的配置是这样的:

<value>classpath:master.hibernate.cfg.xml</value> 

这工作,如果你的master.hibernate.cfg.xml在你的资源。

0

你可以尝试下面的代码来指出弹簧的正确位置hibernate.cfg.xml

<bean 
    id="mySessionFactory" 
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 

    <property name="configLocation">  
     <value> 
      classpath:location_of_config_file/hibernate.cfg.xml 
     </value> 
    </property> 
........... 
</bean> 
相关问题