zoukankan      html  css  js  c++  java
  • ssh框架————1

    1、创建maven项目

    2、pom.xml文件

    <properties>
               <!-- 单元测试框架 -->
               <!-- 需要导入相应jar包:junit-4.12.jar、hamcrest-core-1.3.rc2.jar、hamcrest-library-1.3.rc2.jar 
           JUnit4注解解释
    			1. @Test : 测试方法,测试程序会运行的方法,后边可以跟参数代表不同的测试,如(expected=XXException.class) 异常测试,
                      (timeout=xxx)超时测试 2. @Ignore : 被忽略的测试方法 3. @Before: 每一个测试方法之前运行 4. @After : 每一个测试方法之后运行 5. @BeforeClass: 所有测试开始之前运行 6. @AfterClass: 所有测试结束之后运行 --> <junit.version>4.12</junit.version> <!-- servlet--> <servlet.version>3.0.1</servlet.version> <!-- JSP Standard Tag Library,JSP标准标签库 需要jstl.jar和taglits.jar--> <jstl.version>1.2</jstl.version> <taglibs.version>1.1.2</taglibs.version> <!-- hibernate --> <hibernate.version>4.3.9.Final</hibernate.version> <!-- mysql --> <mysql.version>5.1.40</mysql.version> <!-- spring --> <spring.version>4.2.8.RELEASE</spring.version> <!-- 高性能的 JDBC 连接池 --> <hikaricp.version>2.6.1</hikaricp.version> </properties>

     3、applicationContext-db.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:tx="http://www.springframework.org/schema/tx" 
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
           http://www.springframework.org/schema/context 
           http://www.springframework.org/schema/context/spring-context-4.0.xsd
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
           
               
        <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource"
            destroy-method="close">
            <constructor-arg>
                <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
                    <property name="dataSourceProperties">
                        <props>
                            <prop key="url">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8</prop>
                            <prop key="user">user</prop>
                            <prop key="password">password</prop>
                            <prop key="prepStmtCacheSize">250</prop>
                            <prop key="prepStmtCacheSqlLimit">2048</prop>
                            <prop key="cachePrepStmts">false</prop> <!-- 缓存关闭,否则各种断开连接 -->
                            <prop key="useServerPrepStmts">true</prop>
                        </props>
                    </property>
                    <property name="poolName" value="springHikariCP" />
                    <property name="connectionTestQuery" value="SELECT 1" />
                    <property name="dataSourceClassName"
                        value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
                    <!-- 处于空闲状态的连接超时释放设置,单位毫秒 -->
                    <property name="idleTimeout" value="600000"/>
                    <!-- 链接的最大时长,单位毫秒 -->
                    <property name="maxLifetime" value="3600000"/>
                    <!-- 链接池可创建的最大连接数 -->
                    <property name="maximumPoolSize" value="15"/>
                    <!-- Default settings -->
                    <!-- 控制自动提交行为 default:true -->
                    <property name="autoCommit" value="true" />
                    <!--连接池获取的连接是否只读 default:false -->
                    <property name="readOnly" value="false" />
                    <!--控制连接的事务隔离等级 default:none -->
                    <property name="transactionIsolation" value="TRANSACTION_REPEATABLE_READ" />
                    <!--从池中获取连接的超时时间 default:30秒 -->
                    <property name="connectionTimeout" value="30000" />
                    <property name="allowPoolSuspension" value="false" />
                    <!--<property name="minimumIdle" value="20" /> -->
                </bean>
            </constructor-arg>
        </bean>
        
        <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"/>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.connection.release_mode">auto</prop>
                    <prop key="hibernate.autoReconnect">true</prop>
                    <prop key="hibernate.jdbc.batch_size">30</prop>
                </props>
            </property>
            <property name="packagesToScan" value="com.uu.demo.spring.ssh.entiey"/>
        </bean>
        
        <!-- 事务管理器 -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" >
            <property name="sessionFactory" ref="sessionFactory"/>
        </bean>
        
        <!-- 定义事务Advice,即定义事务实际控制者,这里借助HibernateTransactionManager来进行事务控制,并设置相关属性 -->
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="get*" propagation="REQUIRED" read-only="true" />
                <tx:method name="find*" propagation="REQUIRED" read-only="true" />
                <tx:method name="query*" propagation="REQUIRED" read-only="true" />
                <tx:method name="search*" propagation="REQUIRED" read-only="true" />
                <tx:method name="select*" propagation="REQUIRED" read-only="true" />
                <tx:method name="count*" propagation="REQUIRED" read-only="true" />
                <tx:method name="*" propagation="REQUIRED" />
            </tx:attributes>
        </tx:advice>
    
        <!-- 事务切面配置 -->
        <aop:config proxy-target-class="true">
            <!-- 设定哪些POJO类将纳入事务控制 -->
            <aop:pointcut id="txPoint"
                expression="execution(* com.uu.demo.spring.ssh.dao..*(..))" />
            <!-- 定义由谁来进行实际事务控制,这里当然是txAdvice(最终由HibernateTransactionManager来控制) -->
            <aop:advisor advice-ref="txAdvice" pointcut-ref="txPoint"
                order="1" />
        </aop:config>
        
        <!-- 扫描注解类 -->
        <context:component-scan base-package="com.uu.demo.spring.ssh.dao"/>
        
    </beans>
  • 相关阅读:
    MongoDB ODM
    MongoDb python连接
    json格式化
    IDEA使用
    centos7安装完mariadb设置初始密码
    linux虚机联网
    问题解决记录【612-714】
    资料积累
    技术名词理解
    eclipse
  • 原文地址:https://www.cnblogs.com/kongkongFabian/p/6790773.html
Copyright © 2011-2022 走看看