1、META-INF下persistence.xml文件
- <?xml version="1.0" encoding="UTF-8"?>
- <persistence xmlns="http://java.sun.com/xml/ns/persistence"
- version="2.0">
- <!--
- <persistence-unit name="common" transaction-type="RESOURCE_LOCAL">
- <provider>org.hibernate.ejb.HibernatePersistence</provider>
- <properties>
- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
- <property name="hibernate.show_sql" value="true" />
- <property name="hibernate.format_sql" value="true" />
- <property name="hibernate.use_sql_comments" value="false" />
- <property name="hibernate.hbm2ddl.auto" value="update" />
- </properties>
- </persistence-unit>
- -->
- <persistence-unit name="common" />
- </persistence>
2、spring配置文件
- <?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:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
- xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
- http://www.springframework.org/schema/data/jpa
- http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
- <context:component-scan base-package="com.langaili.dao" />
- <context:component-scan base-package="com.langaili.service" />
- <!-- 定义上下文返回的消息的国际化。
- <bean id="messageSource"
- class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
- <property name="basename"
- value="classpath:org/springframework/security/messages_zh_CN" />
- </bean>
- -->
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
- destroy-method="close">
- <property name="driverClassName" value="com.mysql.jdbc.Driver" />
- <property name="url"
- value="jdbc:mysql://localhost/fanka?useUnicode=true&characterEncoding=utf-8&autoReconnect=true" />
- <property name="username" value="root" />
- <property name="password" value="password" />
- </bean>
- <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
- <property name="dataSource" ref="dataSource" /> <property name="packagesToScan">
- <value>com.langaili.domain</value> </property> <property name="hibernateProperties">
- <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQL5InnoDBDialect
- </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop>
- <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> -->
- <!--
- <bean id="entityManagerFactory"
- class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="persistenceUnitName" value="common"></property>
- <property name="packagesToScan" value="com.langaili.domain" />
- <property name="dataSource" ref="dataSource" />
- </bean>
- -->
- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="persistenceUnitName" value="common" />
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
- <property name="showSql" value="true" />
- <property name="generateDdl" value="true" />
- <property name="database" value="MYSQL" />
- </bean>
- </property>
- <property name="jpaProperties">
- <props>
- <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
- <prop key="hibernate.format_sql">true</prop>
- <prop key="hibernate.hbm2ddl.auto">update</prop>
- </props>
- </property>
- </bean>
- <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
- <property name="entityManagerFactory" ref="entityManagerFactory" />
- </bean>
- <jpa:repositories base-package="com.langaili.dao"
- entity-manager-factory-ref="entityManagerFactory"
- transaction-manager-ref="transactionManager">
- <!-- <jpa:repository id="userRepository" custom-impl-ref="userRepositoryCustom"/> -->
- </jpa:repositories>
- <tx:annotation-driven transaction-manager="transactionManager"/>
- </beans>