• 最全三大框架整合(使用映射)——applicationContext.xml里面的配置


         applicationContext.xml:

     1     <?xml version="1.0" encoding="UTF-8"?>  
     2     <beans  
     3         xmlns="http://www.springframework.org/schema/beans"  
     4         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     5         xmlns:p="http://www.springframework.org/schema/p"  
     6         xmlns:aop="http://www.springframework.org/schema/aop"  
     7         xmlns:tx="http://www.springframework.org/schema/tx"  
     8         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
     9         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
    10         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
    11         " default-autowire="byName">  
    12       
    13           
    14         <!-- 配置数据源 -->  
    15         <bean id="config" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
    16             <property name="locations">  
    17                 <list>  
    18                     <value>classpath:jdbc.properties</value>  
    19                 </list>  
    20             </property>  
    21         </bean>  
    22           
    23         <!-- dataSource -->  
    24         <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  
    25             <property name="url" value="${jdbc.url}"></property>  
    26             <property name="driverClassName" value="${jdbc.driver}"></property>  
    27             <property name="username" value="${jdbc.username}"></property>  
    28             <property name="password" value="${jdbc.password}"></property>  
    29         </bean>  
    30         <!-- sessionFaction -->  
    31         <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
    32             <property name="dataSource" ref="dataSource"></property>  
    33             <property name="hibernateProperties">  
    34                 <props>  
    35                     <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>  
    36                     <prop key="hibernate.show_sql">true</prop>  
    37                     <prop key="hibernate.format_sql">true</prop>  
    38                 </props>  
    39             </property>  
    40             <property name="mappingDirectoryLocations">  
    41                 <list>  
    42                     <value>classpath:org/entity</value>  
    43                 </list>  
    44             </property>  
    45         </bean>  
    46           
    47         <!-- 事务 -->  
    48          <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
    49             <property name="sessionFactory" ref="sessionFactory"></property>  
    50         </bean>  
    51           
    52         <!-- 增强 -->  
    53         <tx:advice id="txAdvice" transaction-manager="txManager">  
    54             <tx:attributes>  
    55                 <tx:method name="add*" propagation="REQUIRED"/>  
    56                 <tx:method name="save*" propagation="REQUIRED"/>  
    57                 <tx:method name="update*" propagation="REQUIRED"/>  
    58                 <tx:method name="del*" propagation="REQUIRED"/>  
    59                 <tx:method name="get*" read-only="true"/>  
    60                 <tx:method name="find*" read-only="true"/>  
    61                 <tx:method name="query*" read-only="true"/>  
    62                 <tx:method name="*"/>  
    63             </tx:attributes>  
    64         </tx:advice>  
    65         <aop:config>  
    66             <aop:pointcut id="mycut" expression="execution(* org.service..*.*(..))" />  
    67             <aop:advisor advice-ref="txAdvice" pointcut-ref="mycut"/>  
    68         </aop:config>   
    69           
    70           
    71           
    72         <!-- 引入dao层 -->  
    73         <import resource="applicationContext-dao.xml"/>  
    74         <!-- 引入service层 -->  
    75         <import resource="applicationContext-service.xml"/>  
    76         <!-- 引入action层 -->  
    77         <import resource="applicationContext-action.xml"/>  
    78         </beans>  

    2.     applicationContext-action.xml:

     1     <?xml version="1.0" encoding="UTF-8"?>  
     2     <beans  
     3         xmlns="http://www.springframework.org/schema/beans"  
     4         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     5         xmlns:p="http://www.springframework.org/schema/p"  
     6         xmlns:aop="http://www.springframework.org/schema/aop"  
     7         xmlns:tx="http://www.springframework.org/schema/tx"  
     8         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
     9         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
    10         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
    11         " default-autowire="byName">  
    12             <bean id="deptAction" class="org.web.DeptAction"></bean>  
    13         </beans>  

     转自:https://blog.csdn.net/qq_34137397/article/details/72823031

    3.     applicationContext-dao.xml:

     1     <?xml version="1.0" encoding="UTF-8"?>  
     2     <beans  
     3         xmlns="http://www.springframework.org/schema/beans"  
     4         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     5         xmlns:p="http://www.springframework.org/schema/p"  
     6         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
     7         " default-autowire="byName">  
     8               
     9         <!-- 配置DAO -->  
    10         <bean id="deptDao" class="org.dao.impl.DeptDaoImpl">  
    11             <property name="sessionFactory" ref="sessionFactory"></property>  
    12         </bean>  
    13           
    14         </beans>  

    4.     applicationContext-service.xml:

     1     <?xml version="1.0" encoding="UTF-8"?>  
     2     <beans  
     3         xmlns="http://www.springframework.org/schema/beans"  
     4         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
     5         xmlns:p="http://www.springframework.org/schema/p"  
     6         xmlns:aop="http://www.springframework.org/schema/aop"  
     7         xmlns:tx="http://www.springframework.org/schema/tx"  
     8         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd  
     9         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd  
    10         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd  
    11         " default-autowire="byName">  
    12             <bean id="deptService" class="org.service.impl.DeptServiceImpl"></bean>  
    13         </beans>  
  • 相关阅读:
    IO模型
    函数第一类对象,闭包,迭代器
    admin里面的注册模型类的写法
    升级pip
    Windows部署superset操作手册
    Python命名空间和作用域窥探
    使用CSS3画出一个叮当猫
    D
    [java]说说 JRE , JDK , JVM 三者之间的区别与联系
    H~N皇后问题
  • 原文地址:https://www.cnblogs.com/sharpest/p/7719055.html
Copyright © 2020-2023  润新知