SSH的配置文件(1)

来源:互联网 发布:linux查找文件夹 编辑:程序博客网 时间:2024/05/17 05:18

ssh的applicationContext.xml的配置

<?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:p="http://www.springframework.org/schema/p"  
    xmlns:aop="http://www.springframework.org/schema/aop"   
    xmlns:context="http://www.springframework.org/schema/context"  
    xmlns:jee="http://www.springframework.org/schema/jee"  
    xmlns:tx="http://www.springframework.org/schema/tx"  
    xsi:schemaLocation="    
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd  
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd  
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
    
    <!-- 加载属性文件 -->
    <context:property-placeholder location="classpath:database.properties"/>
    
    <!-- 创建dataSource -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  
        destroy-method="close">  
        <property name="jdbcUrl" value="${jdbc.url}"></property>  
        <property name="driverClass" value="${jdbc.driverClassName}"></property>  
        <property name="user" value="${jdbc.username}"></property>  
        <property name="password" value="${jdbc.password}"></property>
        <!-- 连接池中最大的连接数量 -->
        <property name="maxPoolSize" value="40"></property>
        <!-- 连接池中最少的连接数量 --> 
        <property name="minPoolSize" value="3"></property>
        <!-- 连接池中初始的连接数量 -->  
        <property name="initialPoolSize" value="5"></property>  
        <property name="maxIdleTime" value="20"></property>  
    </bean>
    
    <!-- sessionFactory -->
    <bean id="sessionFactory"  
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!-- 设置数据源 -->  
        <property name="dataSource">  
            <ref bean="dataSource" />  
        </property>
        <!-- 设置hibernate的配置文件 -->
        <property name="configLocation" value="classpath:hibernate.cfg.xml"/>  
        <!-- hibernate如果使用的注解方式,则需要添加下面的配置。用途:自动扫描注解方式配置的hibernate类文件 -->  
        <property name="packagesToScan">  
            <list>  
                <value>com.wskj.ssh.entity</value>  
            </list>
        </property> 
    </bean>
    
    <!-- dao -->
    <bean id="logCategoryDao" class="com.tencent.qqzone.dao.impl.LogCategoryDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    
    <bean id="logDao" class="com.tencent.qqzone.dao.impl.LogInfoDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    
    <!-- service -->
    <bean id="logService" class="com.tencent.qqzone.service.impl.LoggerServiceImpl">
    <property name="logCategoryDao" ref="logCategoryDao"></property>
    <property name="logDao" ref="logDao"></property>
    </bean>
    
    <!-- action -->
    <bean id="loggerAction" class="com.tencent.qqzone.controller.LoggerAction">
    <property name="logService" ref="logService"></property>
    </bean>
    
    <!-- 事务 -->
    <!-- 1.配置事务管理器 -->
<bean id="transactionManager"  
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory" />  
    </bean>
    
    <!-- 2.配置事务增强 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">  
        <!-- 定义事务传播属性 -->  
        <tx:attributes>  
            <tx:method name="insert*" propagation="REQUIRED" />  
            <tx:method name="update*" propagation="REQUIRED" />  
            <tx:method name="edit*" propagation="REQUIRED" />  
            <tx:method name="save*" propagation="REQUIRED" />  
            <tx:method name="add*" propagation="REQUIRED" />  
            <tx:method name="new*" propagation="REQUIRED" />  
            <tx:method name="set*" propagation="REQUIRED" />  
            <tx:method name="remove*" propagation="REQUIRED" />  
            <tx:method name="delete*" propagation="REQUIRED" />  
            <tx:method name="change*" propagation="REQUIRED" />  
            <tx:method name="get*" propagation="REQUIRED" read-only="true" /> 
            <tx:method name="query*" propagation="REQUIRED" read-only="true" /> 
            <tx:method name="find*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="load*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="search*" propagation="REQUIRED" read-only="true" />  
            <tx:method name="*" propagation="REQUIRED" read-only="true" />  
        </tx:attributes>  
    </tx:advice>
    
    <!-- 3.配置事务的切入点和增强 -->
    <aop:config>  
        <aop:pointcut id="serviceOperation"  
            expression="execution(* com.tencent.qqzone.service..*.*(..))" />  
        <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
    </aop:config>
    
</beans>
0 0