zoukankan      html  css  js  c++  java
  • spring5+Struts2+hibernate5

    一,加jar包

    加入顺序,个人推荐,spring->struts2->hibernate

        spring的jar包:基本包共21个+用到的aspectj注解的包2个+日志包1个

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        struts2的jar包:基本包共8个+1个(这个包的功能struts2的action交给spring容器管理)

    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

        hibernate的jar包:基本包共10个+c3p0数据源的包+数据库驱动

     

    ----至此,所有的jar包都加完了----

     二,加配置文件

    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: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.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
    
        <context:component-scan base-package="convict"></context:component-scan>
        <context:property-placeholder location="classpath:db.properties"/>
        
        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <property name="user" value="${jdbc.user}"></property>
            <property name="password" value="${jdbc.password}"></property>
            <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
            <property name="driverClass" value="${jdbc.driverClass}"></property>
            <property name="initialPoolSize" value="${jdbc.initPoolSize}"></property>
            <property name="maxPoolSize" value="${jdbc.maxPoolSize}"></property>
        </bean>
        
        <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
        </bean>
        
        <!-- 配置事务管理器 -->
        <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
            <property name="dataSource" ref="dataSource"></property>
            <property name="sessionFactory" ref="sessionFactory"></property>
        </bean>
        <!-- 启用事务注解 -->
        <tx:annotation-driven transaction-manager="transactionManager"/>
    </beans>

    struts.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>
        <constant name="struts.enable.DynamicMethodInvocation" value="false" />
        <package name="default" namespace="/" extends="struts-default">
            <action name="register" class="registerAction">
                <result name="success">/welcome.jsp</result>
            </action>
        </package>
    </struts>

    hibernate.cfg.xml

    <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
        <session-factory>
            <property name="show_sql">true</property>
            <property name="hibernate.hbm2ddl.auto">update</property>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
            
            <mapping class="convict.po.User"/>
        </session-factory>
    </hibernate-configuration>

    db.properties

    jdbc.user=root
    jdbc.password=12345678
    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.jdbcUrl=jdbc:mysql://localhost/db_ssh_comp
    
    jdbc.initPoolSize=5
    jdbc.maxPoolSize=10

    三,加各种包,jsp,action等,如图

    四,项目文件太多不一一放上来,有需要可以去下载,https://gitee.com/convicts/ssh_integration_case,点个 star 吖

  • 相关阅读:
    jQuery插件 -- 表单验证插件jquery.validate.js
    jQuery插件 -- Form表单插件jquery.form.js<转>
    win7 64位安装oracle10g客户端心得
    用STS创建Maven的Web项目<转>
    分别通过【buildpath】和【lib】倒入JAR包有什么不同
    利用AbstractRoutingDataSource实现动态数据源切换
    mybatis分页
    Java基本功—Reference
    Java中 堆 栈,常量池等概念解析(转载)
    RTSP流媒体转发服务器源码
  • 原文地址:https://www.cnblogs.com/convict/p/9056160.html
Copyright © 2011-2022 走看看