spring学习笔记---------applicationContext.xml 1

<?xml version="1.0" encoding="UTF-8"?>
    <!--
        最基本命名空间定义
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        
        xsi:schemaLocation:与上述 最基本命名空间定义 相配套的schema定义文件的 路径
        
        xmlns:p="http://www.springframework.org/schema/p"
        可以使用 这种方式添加属性值
        <bean id="test" class="com.cococake.test.Test" p:song = "Jingle Bells"/>
        
        启用自动扫描或注解装配的命名空间
        xmlns:context="http://www.springframework.org/schema/context"
        启用声明事务的命名空间
        xmlns:tx="http://www.springframework.org/schema/tx"
        启用aop功能时的命名空间
        xmlns:aop="http://www.springframework.org/schema/aop"
        
        自动装配
        default-autowire="byName"
     -->
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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:aop="http://www.springframework.org/schema/aop"
    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/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
        "
    default-autowire="byName">
    <!-- 开启注解处理器 -->
    <context:annotation-config />
    <!-- 开启组件自动扫描 -->
    <context:component-scan base-package="com.cococake.service"/>
    <!-- 开启基于aspectj的切面注解处理器 -->
    <aop:aspectj-autoproxy/>
    <!-- 注入service dao -->
    <bean id="registerDao" class="com.cococake.dao.impl.RegisterDaoImpl"/>  
    <bean id="registerService" class="com.cococake.service.impl.RegisterServiceImpl"/>  
    <bean id="productDao" class="com.cococake.dao.impl.ProductDaoImpl"/>  
    <bean id="productService" class="com.cococake.service.impl.ProductServiceImpl" init-method="init"/>  
    
    <bean id="test" class="com.cococake.test.Test" p:song = "Jingle Bells" init-method="init" destroy-method="destroy"
        scope="singleton"/>
    <!-- ==============================aop start===========================  -->
     <!-- 日志切面类 -->  
     <bean id="logAspectBean" class="com.cococake.aspect.LogAnnotationAspect"/>
    <!-- <bean id="logAspectBean" class="com.cococake.aspect.LogAspect"/> -->
     <!-- 第1步: AOP的配置 -->   
    <!-- <aop:config>
         第2步:配置一个切面  
        <aop:aspect id="logAspect" ref="logAspectBean">
            第3步:定义切入点,指定切入点表达式
            execution   是方法运行
                public         是指定public的方法,也可以不写直接:execution(* cn.dao.IUserDAO.*(..)
                
                *                  是任意返回值,可以有返回值,也可以是void没有返回值的方法
                
                cn.dao.IUserDAO.*                  是指定目录下的指定类任意方法
                
                cn.dao.IUserDAO.insert*       是指定目录下的指定类insert开头的任意方法
                
                cn.dao.IUserDAO.*.*              是指定目录下的任意类下的任意方法
                
                cn.dao..*.*                                是指定目录下的任意目录下任意类下的任意方法
                
                (..)                                              是任何参数,可以是没有参数
            
            <aop:pointcut id="allMethod"   
                expression="execution(* com.cococake.service.*.*(..))"/>   
            第4步:应用前置通知  
            <aop:before method="before" pointcut-ref="allMethod" />  
            第4步:应用后置通知  
            <aop:after-returning method="afterReturn" pointcut-ref="allMethod"/>  
            第4步:应用最终通知  
            <aop:after method="after" pointcut-ref="allMethod"/>  
            第4步:应用抛出异常后通知  
            <aop:after-throwing method="afterThrowing" pointcut-ref="allMethod"/>  
            第4步:应用环绕通知  
             
            <aop:around method="doAround" pointcut-ref="allMethod" />
              
        </aop:aspect>
        
    </aop:config> -->
    <!-- hibernate事务管理器切入点 -->
    <!-- ======================== aop end ============================= -->
    <aop:config>
        <aop:pointcut id="serviceMethod" expression="execution(* com.cococake.service.*.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
    </aop:config>
    <!-- 配置数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/cococake?useUnicode=true&amp;characterEncoding=UTF-8"/>
        <property name="user" value="root"/>
        <property name="password" value="qwer1111"/>
   </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.MySQLDialect
                </prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <!-- 注解类声明 -->
        <!-- <property name="annotatedClasses">
            <list>
                <value>com.cococake.bean.user.User</value>
            </list>
        </property> -->
        <!-- 实体类扫描-->
        <property name="packagesToScan">
            <list>
                <value>com.cococake.bean.*</value>
                <value>com.cococake.bean</value>
            </list>
        </property>
    </bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!-- 支持注解配置事务管理器 -->
    <tx:annotation-driven transaction-manager="transactionManager" />
    <!--事物规则-->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="save*" propagation="REQUIRED"/>
            <tx:method name="update*"  propagation="REQUIRED"/>
            <tx:method name="delete*" propagation="REQUIRED"/>
            <tx:method name="saveOrUpdate*" propagation="REQUIRED"/>
            <tx:method name="register*" propagation="REQUIRED"/>
            <tx:method name="list*" read-only="true"/>
            <tx:method name="get*" read-only="true"/>
        </tx:attributes>
    </tx:advice>
    
</beans>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值