• ssh入门教程


    1、在myeclipse中新建web项目,点击右键选择Myeclipse-->添加sping框架支持

    3、添加hibernate框架支持

    3、添加struts框架支持

    4、修改一下web.xml

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </context-param>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

    5、修改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:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd  
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
    
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver">
            </property>
            <property name="url" value="jdbc:mysql://192.168.1.200:3306/test">
            </property>
            <property name="username" value="taobao"></property>
            <property name="password" value="1234"></property>
        </bean>
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="dataSource">
                <ref bean="dataSource" />
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">
                        org.hibernate.dialect.MySQLDialect
                    </prop>
                </props>
            </property>
        </bean>
        <!-- 事物配置 -->
        <bean id="transactionManager"
            class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"></property>
        </bean>
        <tx:advice id="txAdvice" transaction-manager="transactionManager">
            <tx:attributes>
                <tx:method name="get*" read-only="true" />
                <tx:method name="find*" read-only="true" />
                <tx:method name="add*" propagation="REQUIRED" />
                <tx:method name="save*" propagation="REQUIRED" />
                <tx:method name="delete*" propagation="REQUIRED" />
            </tx:attributes>
        </tx:advice>
        <aop:config>
            <aop:pointcut id="myPointcut"
                expression="execution(public * com.hnhcc.dao..*.*(..))" />
            <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointcut" />
        </aop:config>
    </beans>

    6、添加spring和hibernate的顺序无所谓的,但是struts要在hibernate之后,原因是antlr.jar有冲突,当然手动删除也没关系的,如果先添加spring再添加hiernate,那些连接数据库的信息是写在applicationContext.xml里的,如果是先添加hibernate再添加spring,则连接信息是在hibernate.cfg.xml,当然applicationContext.xml中的连接数据库的bean也会有点不一样

    spring-->hibernateheibernate-->spring

        <bean id="sessionFactory"
            class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
            <property name="configLocation" value="classpath:hibernate.cfg.xml">
            </property>
        </bean>
  • 相关阅读:
    ssh登陆报错“WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!”的解决方法
    python错误:SyntaxError: invalid character in identifier
    Python3中出现UnicodeEncodeError: 'ascii' codec can't encode characters in ordinal not in range(128)的解决方法
    Jmeter在Mac下安装教程
    TensorFlow | win10下使用docker安装tensorflow
    Docker | 删除 image 失败的一种情况
    基础技能 | Git
    Leetcode-探索 | 两数之和
    Leetcode-探索 | 移动零
    基础复习-算法设计基础 | 复杂度计算
  • 原文地址:https://www.cnblogs.com/hnhcc39/p/2939152.html
Copyright © 2020-2023  润新知