<!-- 1.dataSource 配置数据库连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/springdatajpa9502" />
<property name="user" value="root" />
<property name="password" value="root" />
</bean>
<!--工厂类对象-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!--配置数据源-->
<property name="dataSource" ref="dataSource"/>
<!--实体类的包扫描器-->
<property name="packagesToScan" value="com.itheima.jpa.entity"/>
<!--配置供应商适配器-->
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!--是否向控制台输出sql语句-->
<property name="showSql" value="true"/>
<!--是否自动创建表
如果是true:相当于update,hibernate.hbm2ddl.auto属性配置成update
如果是false:相当于none
-->
<property name="generateDdl" value="true"/>
<!--使用的数据库类型-->
<property name="database" value="MYSQL"/>
</bean>
</property>
</bean>
<!--配置事务-->
<!-- 3.事务配置-->
<!-- 3.1JPA事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<!-- 3.2.txAdvice-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
// 开启事务
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="find*" read-only="true"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 3.3.aop-->
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* cn.lijun.jpa.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
</aop:config>
<!--dao的包扫描器-->
<jpa:repositories base-package="cn.lijun.jpa.dao"
transaction-manager-ref="transactionManager"// 事务管理器
entity-manager-factory-ref="entityManagerFactory"/>// 工厂类