• JavaEE笔记(十四)


    #SSH配置文件整合笔记实例

    spring-BaseBean.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: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/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.2.xsd
            http://www.springframework.org/schema/tx
            http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
        <!-- 读取db.propertieds配置文件 -->
        <context:property-placeholder location="classpath:db.properties" />
        <!-- 配置连接池c3p0 -->
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close">
            <property name="driverClass" value="${driverClass}" />
            <property name="jdbcUrl" value="${jdbcUrl}" />
            <property name="user" value="${user}" />
            <property name="password" value="${password}" />
            <!--当连接池中的连接用完时,C3P0一次性创建新连接的数目 -->
            <property name="acquireIncrement" value="${acquireIncrement}" />
            <!--初始化时创建的连接数,应在minPoolSize与maxPoolSize之间取值 -->
            <property name="initialPoolSize" value="${initialPoolSize}" />
            <!--minPoolSize连接池 最少连接数 -->
            <property name="minPoolSize" value="${minPoolSize}" />
            <!--maxPoolSize连接池 最大连接数 -->
            <property name="maxPoolSize" value="${maxPoolSize}" />
            <!--maxIdleTime最大空闲时间 -->
            <property name="maxIdleTime" value="${maxIdleTime}" />
        </bean>
    
        <!-- 配置sessionFactory -->
        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />
            <property name="mappingResources">
                <!-- 配置hibernate文件 -->
                <list>
                    <value>com/pet/bean/xml/PetDiary.hbm.xml</value>
                    <value>com/pet/bean/xml/PetInfo.hbm.xml</value>
                </list>
            </property>
            <!-- 配置hibernate系统执行读取配置文件 -->
            <property name="hibernateProperties">
                <value>
                    hibernate.dialect=org.hibernate.dialect.MySQLDialect
                    hibernate.show_sql=true
                    hibernate.hbm2ddl.auto=update
                    hibernate.format_sql=true
                </value>
            </property>
        </bean>
    
        <!-- 开启事物管理 -->
        <bean id="transactionManager"
            class="org.springframework.orm.hibernate4.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
    
        <aop:config>
            <aop:pointcut id="pointcut" expression="execution(* com.pet.dao.*.*(..))" />
            <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut" />
        </aop:config>
    
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="insert*" propagation="REQUIRED" />
                <tx:method name="update*" propagation="REQUIRED" />
                <tx:method name="delete*" propagation="REQUIRED" />
                <tx:method name="select*" read-only="true" />
            </tx:attributes>
        </tx:advice>
        <!-- 配置bean对象 -->
        <bean id="PetDiaryDaoImpl" class="com.pet.dao.impl.PetDiaryDaoImpl">
    
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
        <bean id="PetInfoDaoImpl" class="com.pet.dao.impl.PetInfoDaoImpl">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>
        <bean id="PetDiaryServiceImpl" class="com.pet.service.impl.PetDiaryServiceImpl">
            <property name="petDiaryDaoImpl" ref="PetDiaryDaoImpl" />
        </bean>
        <bean id="PetInfoServiceImpl" class="com.pet.service.impl.PetInfoServiceImpl">
            <property name="petInfoDaoImpl" ref="PetInfoDaoImpl" />
        </bean>
    </beans>    

    db.properties

    driverClass=com.mysql.jdbc.Driver
    jdbcUrl=jdbc:mysql://127.0.0.1:3306/javaee
    user=root
    password=765800
    acquireIncrement=10
    initialPoolSize=10
    minPoolSize=3
    maxPoolSize=500
    maxIdleTime=1800

    spring-ActionBean.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"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
    
        <bean id="PetInfoAction" class="com.pet.struts.PetInfoAction">
            <property name="petInfoServiceImpl" ref="PetInfoServiceImpl"/>
        </bean>
    </beans>    

    struts.xml

    <?xml version="1.0" encoding="UTF-8"?>
    
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
    
    <struts>
        <!-- 开启开发者模式 -->
        <constant name="struts.devMode" value="true" />
        <!--把struts生产action的权利交给spring -->
        <constant name="struts.objectFactory" value="spring" />
        
        <package name="student" extends="json-default" namespace="/">
            <action name="pet_*" class="PetInfoAction"
                method="{1}">
                <result type="json"/>
                <allowed-methods>
                    selectAllPets,delete,selectById,insert
                </allowed-methods>
            </action>
        </package>
    </struts>

    ps:配置文件仅供参考

    我不作恶

    但有权拒绝为善

    我不赞同

    但是我捍卫你不为善的权力

  • 相关阅读:
    django 之 ContentType的使用
    redis的使用与 django的redis的使用
    django之缓存的用法, 文件形式与 redis的基本使用
    python全栈脱产第20天------常用模块---re模块和subprocess模块
    python全栈脱产第19天------常用模块---shelve模块、xml模块、configparser模块、hashlib模块
    python全栈脱产第4天------if判断、while和for循环、数据类型(int和float)
    python全栈脱产第18天------包的使用和logging模块
    python全栈脱产第5天------字符串(str)类型和列表(list)类型
    python全栈脱产第17天------常用模块---time模块、datetime模块、shutil模块、random模块、sys模块、os模块、pickle模块、json模块
    python全栈脱产第16天------模块循环导入问题、区分python文件类型的途径、文件的搜索路径、软件开发的目录规范
  • 原文地址:https://www.cnblogs.com/HackerBlog/p/6170850.html
Copyright © 2020-2023  润新知