• SSH基本框架搭建的详细过程


    **创建一个web工程

    *引入jar包和配置文件

    struts2:

      * jar包:

        struts-2.3.15.3appsstruts2-blank.warWEB-INFlib*.jar

        struts-2.3.15.3libstruts2-json-plugin-2.3.15.3.jar

        struts-2.3.15.3libstruts2-spring-plugin-2.3.15.3.jar

    * 配置文件:

    * web.xml

    1 <filter>
    2      <filter-name>struts2</filter-name>
    3      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    4  </filter>
    5  
    6  <filter-mapping>
    7      <filter-name>struts2</filter-name>
    8      <url-pattern>/*</url-pattern>
    9  </filter-mapping>

    *配置struts.xml文件

    *Spring:

      * jar包:

        Spring3.2 开发最基本jar包

        spring-beans-3.2.0.RELEASE.jar

        spring-context-3.2.0.RELEASE.jar

        spring-core-3.2.0.RELEASE.jar

        spring-expression-3.2.0.RELEASE.jar

        com.springsource.org.apache.commons.logging-1.1.1.jar

        com.springsource.org.apache.log4j-1.2.15.jar

       AOP开发

        spring-aop-3.2.0.RELEASE.jar

        spring-aspects-3.2.0.RELEASE.jar

        com.springsource.org.aopalliance-1.0.0.jar

        com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

      Spring Jdbc开发

        spring-jdbc-3.2.0.RELEASE.jar

        spring-tx-3.2.0.RELEASE.jar

      Spring事务管理

        spring-tx-3.2.0.RELEASE.jar

      Spring整合其他ORM框架

        spring-orm-3.2.0.RELEASE.jar

      Spring在web中使用

        spring-web-3.2.0.RELEASE.jar

      Spring整合Junit测试

        spring-test-3.2.0.RELEASE.jar

    * 配置文件:

    * web.xml

    1 <!-- 配置Spring的核心监听器 -->
    2  <listener>
    3      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    4  </listener>
    5  
    6  <context-param>
    7      <param-name>contextConfigLocation</param-name>
    8      <param-value>classpath:bean.xml</param-value>
    9  </context-param>

    *bean.xml

     1 <beans xmlns="http://www.springframework.org/schema/beans"
     2     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     3     xmlns:context="http://www.springframework.org/schema/context"
     4     xmlns:aop="http://www.springframework.org/schema/aop"
     5     xmlns:tx="http://www.springframework.org/schema/tx"
     6     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     7     http://www.springframework.org/schema/beans/spring-beans.xsd
     8     http://www.springframework.org/schema/context
     9     http://www.springframework.org/schema/context/spring-context.xsd
    10     http://www.springframework.org/schema/aop
    11     http://www.springframework.org/schema/aop/spring-aop.xsd
    12     http://www.springframework.org/schema/tx 
    13     http://www.springframework.org/schema/tx/spring-tx.xsd">
    14 </beans>

    * log4j.properties

     1 ### direct log messages to stdout ###
     2 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
     3 log4j.appender.stdout.Target=System.out
     4 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
     5 log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
     6 
     7 ### direct messages to file mylog.log ###
     8 log4j.appender.file=org.apache.log4j.FileAppender
     9 log4j.appender.file.File=c:/mylog.log
    10 log4j.appender.file.layout=org.apache.log4j.PatternLayout
    11 log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
    12 
    13 ### set log levels - for more verbose logging change 'info' to 'debug' ###
    14 
    15 log4j.rootLogger=info, stdout

    Hibernate:

      * jar包:

        * hibernate-distribution-3.6.10.Finalhibernate3.jar

        * hibernate-distribution-3.6.10.Finallib equired*.jar

        * hibernate-distribution-3.6.10.Finallibjpa*.jar

        * slf4j-log4j整合的jar包 :

        * 数据库驱动:

        * 连接池:(c3p0连接池)

        * 配置文件:

        * 没有hibernate的核心配置文件的方式整合:

        * 映射文件:

    *spring核心配置文件bean.xml的初始化:

     1 <!-- 配置连接池 -->
     2     <!-- 引入外部属性文件 -->
     3     <context:property-placeholder location="classpath:jdbc.properties"/>
     4     <!-- 配置c3p0 -->
     5     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
     6         <property name="driverClass" value="${jdbc.driver}"/>
     7         <property name="jdbcUrl" value="${jdbc.url}"/>
     8         <property name="user" value="${jdbc.user}"/>
     9         <property name="password" value="${jdbc.password}"/>
    10     </bean>
    11     
    12     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    13         <!-- 注入连接池 -->
    14         <property name="dataSource" ref="dataSource"/>
    15         <!-- 配置Hibernate的其他的属性 -->
    16         <property name="hibernateProperties">
    17             <props>
    18                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    19                 <prop key="hibernate.show_sql">true</prop>
    20                 <prop key="hibernate.format_sql">true</prop>
    21                 <prop key="hibernate.connection.autocommit">false</prop>
    22                 <prop key="hibernate.hbm2ddl.auto">update</prop>
    23             </props>
    24         </property>
    25         <!-- 配置Hibernate的映射文件 -->
    26     </bean>
    27     
    28     <!-- 事务管理: -->
    29     <!-- 事务管理器 -->
    30     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    31         <property name="sessionFactory" ref="sessionFactory"/>
    32     </bean>
    33     <!-- 开启注解事务 -->
    34     <tx:annotation-driven transaction-manager="transactionManager"/>
  • 相关阅读:
    Python基础__字符串拼接、格式化输出与复制
    Python基础__Python序列基本类型及其操作(1)
    Selenium 元素等待
    Selenium 键盘鼠标实践
    Selenium 元素定位
    Selenium 启动浏览器
    Selenium Webdriver概述
    linux虚拟机安装和xshell远程连接
    python实现dubbo接口的调用
    Python+Appium自动化测试(6)-元素等待方法与重新封装元素定位方法
  • 原文地址:https://www.cnblogs.com/cuibin/p/6803553.html
Copyright © 2020-2023  润新知