Java 如何将hibernate.cfg.xml配置为applicationContext.xml作为数据源?

Java 如何将hibernate.cfg.xml配置为applicationContext.xml作为数据源?,java,mysql,xml,hibernate,spring-mvc,Java,Mysql,Xml,Hibernate,Spring Mvc,我的java根目录中有hibernate.cfg.xml文件 这是我的applicationContext.xml文件 <?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:context="http://www

我的java根目录中有
hibernate.cfg.xml
文件

这是我的
applicationContext.xml
文件

<?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:context="http://www.springframework.org/schema/context"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">

    <context:component-scan base-package="com.nought">
        <context:exclude-filter type="annotation"
            expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

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

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="persistenceUnit" />
        <property name="dataSource" ref="dataSource" />
    </bean>

    <jpa:repositories base-package="com.nought.repository"></jpa:repositories>

</beans>

如何使用hibernate.cfg.xml文件将数据源添加到applicationContext.xml

我还想在applicationContext.xml中实现包含with
org.springframework.orm.hibernate4.LocalSessionFactoryBean
的bean“sessionFactory”

如果是,我想做什么改变


有人能帮我吗?

下面是如何使用hibernate.cfg.xml以及如何使用它配置sessionFactory的示例

cfg.xml

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
    <property name="connection.datasource">java:comp/env/jdbc/oracle</property>
    <property name="dialect">
        org.hibernate.dialect.Oracle9iDialect
    </property>

    .. other config goes here.....
   </session-factory>
</hibernate-configuration>

java:comp/env/jdbc/oracle
org.hibernate.dial.Oracle9iDialect
.. 其他配置在这里。。。。。
将此文件添加到applicationContext.xml中

<bean name="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="configLocation" value="classpath:hibernate.cfg.xml" />
        <property name="mappingResources">
            <list>              
                <value>...your hbm file location...</value>
            </list>
        </property>
    </bean>

…您的hbm文件位置。。。