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:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
       


 <!-- 以下属于hibernate配置 -->
 <!-- 加载jdbc.properties驱动文件 -->
 <context:property-placeholder location="classpath:jdbc.properties"/>
 <!-- 生成数据库 -->
 <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <property name="driverClass" value="${driverClass}"></property>
  <property name="jdbcUrl" value="${jdbcUrl}"></property>
  <property name="user" value="${user}"></property>
  <property name="password" value="${password}"></property>
 </bean>
 <!-- 生成session工厂 -->
 <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
 
  <!-- 1. 核心必须 -->
  <property name="dataSource" ref="dataSource"></property>
  
  <!-- 2. 可选配置 -->
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
   </props>
  </property>
  
  <!-- 3. 映射文件导入 -->
  <property name="mappingDirectoryLocations" value="classpath:com/itheima/bean"></property>
 </bean>
 
 
 <!-- 以下属于spring配置 -->
 <!-- 配置事物管理员 -->
 <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
  <!-- TransactionManager事务管理员依赖工厂,在它父类有工厂属性,所以dao层一定要记得注入sessionFactory-->
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 开启事物 -->
 <tx:annotation-driven transaction-manager="transactionManager"/>
 <!-- AOP注解,需要托管扩展类和被扩展类,打开注解开关-->
 <aop:aspectj-autoproxy/>

 <!-- IOC注解,在xml中配置注解扫描开关-->
  <!-- 告诉spring要去解析类,因为类上有注解 -->
  <context:component-scan base-package="com.itheima.service.impl"/>

 <!-- 以下属于模块配置 -->
 
 <!-- 以下属于用户模块 -->
 <bean id="userAction" class="com.gongsi.web.action.UserAction" scope="prototype">
  <property name="userService" ref="userService"></property>
 </bean>
 
</beans>  

posted @ 2017-12-19 18:17  Dear丶配角  阅读(123)  评论(0编辑  收藏  举报