zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Java高手速成 | Spring、JPA与Hibernate的整合

JAVASpringhibernate 整合 高手 jpa 速成
2023-09-11 14:20:35 时间

01、设置Spring的配置文件

在Spring的配置文件applicationContext.xml中,配置C3P0数据源、EntityManagerFactory和JpaTransactionManager等Bean组件。以下是applicationContext.xml文件的源程序。

/* applicationContext.xml */
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=…>

  <!-- 配置属性文件的文件路径 -->
  <context:property-placeholder 
       location="classpath:jdbc.properties"/>

  <!-- 配置C3P0数据库连接池 -->
  <bean id="dataSource" 
     class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="jdbcUrl" value="${jdbc.url}"/>
    <property name="driverClass" value="${jdbc.driver.class}"/>
    <property name="user" value="${jdbc.username}"/>