configure Spring Data JPA by using XML

if you want to configure Spring Data JPA by using XML configuration (and use the configuration described in the book), you have to follow these steps:

  1. Configure the data source bean.
  2. Configure the entity manager factory bean.
  3. Configure the transaction manager bean.
  4. Enable annotation driven transaction management.
  5. Configure Spring Spring Data JPA.

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:jpa="http://www.springframework.org/schema/data/jpa"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/data/jpa 
    http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.1.xsd">

  
  <jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/CustomerSupport"/>

  
  <bean id="hibernateJpaVendorAdapter" 
    class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

  
  <bean id="entityManagerFactory" 
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
    
    <property name="jpaProperties">
      <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialectprop>
        <prop key="javax.persistence.schema-generation.database.action">noneprop>
        <prop key="hibernate.ejb.use_class_enhancer">trueprop>
      props>
    property>
    
    <property name="packagesToScan" value="foo.bar.model"/>
    
    <property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
    
    <property name="validationMode" value="NONE"/>
  bean>

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

  
  <tx:annotation-driven/>

  
  <jpa:repositories base-package="foo.bar.repository"/>
beans>

你可能感兴趣的:(系统框架)