• SSH整合步骤之注解和非注解


    spring整合hibernate

    加入jar包

    加入spring和aop所需必须包

    加入hibernate的必须包

    spring整合hibernate的必须包

    org.springframework.jdbc-3.1.3.RELEASE.jar

    org.springframework.orm-3.1.3.RELEASE.jar

    org.springframework.transaction-3.1.3.RELEASE.jar

    加入配置文件

    加入spring的配置文件

    加入hibernate的配置文件

    加入配置代码

    加入对SessionFactory的配置

    加入数据源(DataSource)的配置

     <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">

    <property name="driverClass" value="com.mysql.jdbc.Driver"/>

    <property name="url" value="jdbc:mysql://localhost:3306/test"/>

    <property name="username" value="root"/>

    <property name="password" value=""/>

     </bean>

    加入SessionFactory的配置

       <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

    <!-- 配置session factory使用的数据源 -->

    <property name="dataSource" ref="dataSource" />

        <!--原来Hibernate主配置中的内容,拿过来了
    dialect
    show_sql
    format_sql
    Session
    关联小配置
    * update : 最常用的属性,也根据model类生成表,即使表结构改变了,表中的行仍然存在,不会删除以前的行
    * create : 会根据你的model类来生成表,但是每次运行都会删除上一次的表,重新生成表,哪怕2次没有任何改变

    -->
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hibernate.format_sql">true</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>
    </props>
    </property>

      <!--4.DAO-->
    <bean id="bookDAO" class="cn.book.dao.impl.BookDAOImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!--5.Servvice-->
    <bean id="bookService" class="cn.book.service.impl.BookServiceImpl">
    <property name="bookDAO" ref="bookDAO"></property>
    </bean>
    <!--6.action-->
    <bean id="bookAction" class="cn.book.action.BookAction">
    <property name="bookService" ref="bookService"></property>
    </bean>
    <!--7.事务管理器-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <!--8.事务-->
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>


    </beans>

    4

    加入整合包

    加入struts的必须包

    struts整合spring的包

    struts2-spring-plugin-2.3.15.3.jar

    spring整合struts的包

    org.springframework.web-3.1.3.RELEASE.jar

    org.springframework.web.servlet-3.1.3.RELEASE.jar

    org.springframework.web.struts-3.1.3.RELEASE.jar

    5

    加入struts的配置文件struts.xml

    6

    在web.xml中配置struts

      <filter>

    <filter-name>struts2</filter-name>

    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

    </filter>

    <filter-mapping>

    <filter-name>struts2</filter-name>

    <url-pattern>/*</url-pattern>

    </filter-mapping>

    7

    在web.xml配置spring

      <!-- 配置spring的配置文件的位置 -->

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath*:applicationContext-*.xml</param-value>

    </context-param>

    <!-- 配置spring随web容器启动时就创建 -->

    <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    在struts.xml中配置对象创建工具为spring

           <constant name="struts.objectFactory" value="spring" />

  • 相关阅读:
    vs2010装虚拟机后启动慢
    LINUX FIFO(读书笔记,LINUX程序设计第四版)
    WPF控件 ProgressBar
    C# SQLite操作示列
    win10下使用Linux命令
    类初始化与实例化过程
    结构与类 Delphi
    多线程应用 Delphi
    (珍藏)SQL Server中常用的SQL语句
    获取当前用户本地应用程序设置文件夹 Delphi
  • 原文地址:https://www.cnblogs.com/hualishu/p/10020557.html
Copyright © 2020-2023  润新知