java将hibernate配置文件导入Spring applicationContext
我正在尝试将Hibernate3与Spring3.1.0集成。问题是应用程序无法找到在hibernate中声明的映射文件。cfg。xml文件。最初,hibernate配置有数据源配置、hibernate属性和映射hbm。xml文件。 冬眠大师。cfg。xml文件存在于src文件夹中。主文件的外观如下所示:
<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 楼答案
您可以尝试使用下面的代码将spring指向hibernate的正确位置。cfg。xml
# 2 楼答案
在路径的开始处有一个正斜杠,因此在根中查找它。这几乎肯定是不正确的
我通常会这样指定我的配置:
如果你的
master.hibernate.cfg.xml
在你的资源中,这是可行的