zl程序教程

您现在的位置是:首页 >  后端

当前栏目

hibernate与spring整合的配置文档问题详解编程语言

2023-06-13 09:20:31 时间

    context:component-scan base-package= com.wang /   [email protected]
    context:annotation-config/ 提供注释
    ! aop:aspectj-autoproxy/  
   

    !
    aop:config AOP配置
        aop:pointcut id= servicePointcut expression= execution(public * com.wang.service.UserService..*.add(..)) /
        aop:aspect id= logAspect ref= logInterceptor
            aop:before method= before pointcut-ref= servicePointcut /aop:before
        /aop:aspect
    /aop:config

   


    aop:config
        aop:pointcut id= daoPointcut expression= execution(public * com.wang.dao..*.*(..))) /aop:pointcut
        aop:aspect id= logAspect ref= logInterceptor
            aop:before method= before pointcut-ref= daoPointcut /aop:before
        /aop:aspect
    /aop:config

aop:config
        aop:pointcut id= bussinessService expression= execution(public * com.wang.service..*.*(..)) /aop:pointcut
        aop:advisor advice-ref= txAdvice pointcut-ref= bussinessService /aop:advisor
    /aop:config


    bean id= UserService >

    bean id= userDao >

    bean id= logInterceptor >

    bean id= logDao >

    bean id= hibernateTemplate >         property name= sessionFactory ref= mySessionFactory /property

    /bean


    bean id= dataSource >

        property name= driverClassName value= com.mysql.jdbc.Driver /property
        property name= url value= jdbc:mysql://localhost:3306/db_wind /property
        property name= username value= root /property
        property name= password value= 1234 /property
    /bean

    bean id= mySessionFactory >         property name= dataSource ref= dataSource /property
    !
        property name= mappingResources
            list
                value com/wang/model/Log.hbm.xml /value
                value com/wang/model/User.hbm.xml /value
            /list
        /property
   

        property name= packagesToScan 自动到包下查找hibernate注释的model
            list
                value com.wang.model /value
            /list
        /property

        property name= hibernateProperties hibernate属性配置
            props
                prop key= hibernate.dialect
                    org.hibernate.dialect.MySQLDialect
                /prop
                prop key= hibernate.show_sql
                    true
                /prop
            /props
        /property
    /bean

    bean id= txManger >         property name= sessionFactory ref= mySessionFactory /property
    /bean

    ! tx:annotation-driven transaction-manager= txManger /tx:annotation-driven

    tx:advice id= txAdvice transaction-manager= txManger
        tx:attributes
            tx:method name= add* propagation= REQUIRED /
        /tx:attributes
    /tx:advice

   

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/11240.html

cjavamysqlxml