• 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 吖

  • 相关阅读:
    湘志恒善.NET 企业实训新学员必读手册
    周末电脑城有感硬件和软件价格的升降(实物图9.22更新)
    企业I期做项目之前的小例子
    商学院企业I班暑期作业 【2008年8月12日更新】
    项目公司机房升级
    android小应用帮美女更衣系列一(附源码)
    android小应用帮美女更衣系列二(附源码)
    @synthesize 和 @property
    VS2008下载地址和版本破解
    Android腾讯微薄客户端开发十三:提及篇(与我有关的微博)
  • 原文地址:https://www.cnblogs.com/convict/p/9056160.html
Copyright © 2020-2023  润新知