ssh即struts+spring+Hibernate,从头开始学习这个框架。

struts环境配置,首先在apps目录下找到struts2-blank-xxx.war这个文件,这是已经发布好的war包。其中找到lib文件夹,添加其中所有jar到网站lib下面。再找到src/java下面的struts.xml文件,添加到网站的src文件夹中。打开web.xml拷贝struts的核心配置到网站的web.xml,核心配置如下

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

之后,修改struts.xml

<struts>
<!-- 开发模式 -->
<constant name="struts.devMode" value="true" />
<!-- 扩展名配成action -->
<constant name="struts.action.extension" value="action" />
<!-- 主题配置为simple -->
<constant name="struts.ui.theme" value="simple" /> <package name="default" namespace="/" extends="struts-default">
</package> <!-- Add packages here --> </struts>

配置了开发模式,扩展名为action,以及模板为simple

以上就是struts2的配置,之后自己写aciton部分就可以

hibernate配置

添加和ibernate3.jar lib文件夹下required的所有,jpa下的所有,optional下c3p0的所有(数据库连接池),mysql-connector-java-5.1.5-bin,然后把log4j.properties(日志文件)、hibernate.cfg.xml(配置文件),放到网站src目录下.

hibernate.cfg.xml如下

<?xml version='1.0' encoding='utf-8'?>
<!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> <!-- 1,数据库连接信息 -->
<property name="dialect">
org.hibernate.dialect.MySQL5InnoDBDialect
</property>
<!--
<property name="connection.url">jdbc:mysql:///数据库名</property>
<property name="connection.driver_class">com.jdbc.mysql.Driver</property>
<property name="connection.username">数据库用户名</property>
<property name="connection.password">数据库密码</property>
--> <!-- 2,其他配置 -->
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property> <!-- 3,导入映射文件 -->
<mapping resource="cn/itcast/oa/domain/User.hbm.xml" /> </session-factory> </hibernate-configuration>

以上是hibernate的配置

spring配置

添加spring.jar,aspectj文件夹下所有,cglib-nodep-2.1_3.jar,commons-logging.jar(日志),

applicationContext.xml放在src下,代码如下

<?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-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 自动扫描与装配bean -->
<context:component-scan base-package="cn.itcast.oa"></context:component-scan> </beans>

 以上是spring配置

总结一下

Struts2
jar包
struts.xml, web.xml
Hibernate
jar包:核心包, 必须包, jpa, c3p0, jdbc
hibernate.cfg.xml
Spring
jar包
appicationContext.xml

接下来就是要进行整合

首先整合spring和struts2

1.在web.xml中配置Spring的监听器

	<!-- 配置Spring的用于初始化容器对象的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext*.xml</param-value>
</context-param>

2.lib中添加struts2-spring-plugin-2.1.8.1 jar包

这样整合之后struts.xml可以直接写bean的名称

接下来进行Hibernate与Spring整合

1.管理SessionFactory实例(只需要一个)

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 指定hibernate的配置文件位置 -->
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
<!-- 配置c3p0数据库连接池 -->
<property name="dataSource">
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 数据连接信息 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<!-- 其他配置 -->
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="3"></property>
<!--连接池中保留的最小连接数。Default: 3 -->
<property name="minPoolSize" value="3"></property>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="5"></property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="3"></property>
<!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
<property name="maxStatements" value="8"></property>
<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
<property name="maxStatementsPerConnection" value="5"></property>
<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="1800"></property>
</bean>
</property>
</bean>

  2,声明式事务管理

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<tx:annotation-driven transaction-manager="txManager"/>

  

从0开始学习ssh之搭建环境的更多相关文章

  1. pyqt4学习之一:搭建环境和入门

    还在继续写Python小工具,想起之前用Tkinter被坑得半死,决定换个框架写UI,又想顺便了解一下qt,就学习一下pyqt4 搭建环境 win:现在安装包 http://www.riverbank ...

  2. AspectJ基础学习之二搭建环境(转载)

    AspectJ基础学习之二搭建环境(转载) 一.下载Aspectj以及AJDT 上一章已经列出了他的官方网站,自己上去download吧.AJDT是一个eclipse插件,开发aspectj必装,他可 ...

  3. django 学习第一天搭建环境

    目前django版本是1.10,我学习的基础教材是 Web Development with Django Cookbook, Second Edition 搭建好配置环境 ssh免认证登录 修改一下 ...

  4. JAVAEE——BOS物流项目01:学习计划、搭建环境、主页设计(jQuery EasyUI)

    1 学习计划 1.项目概述 项目背景介绍 2.搭建项目开发环境 数据库环境 maven项目搭建 svn环境搭建 3.主页设计(jQuery EasyUI) layout页面布局 accordion折叠 ...

  5. struts2学习笔记--动手搭建环境+第一个helloworld项目

    在Myeclipse中已经内置好了struts2的环境,但是为了更好的理解,这里自己从头搭建一下: 前期准备:下载struts2的完整包,下载地址:https://struts.apache.org/ ...

  6. spring boot学习01【搭建环境、创建第一个spring boot项目】

    1.给eclipse安装spring boot插件 Eclipse中安装Spring工具套件(STS): Help -> Eclipse Marketplace... 在Search标签或者Po ...

  7. Nginx学习系列一搭建环境

    1.Win10下安装vmware14虚拟机软件 官方下载地址 全程next,输入key,激活即可. 2.在虚拟机中安装Linux服务器环境,操作系统为Centos7 继续下一步,安装完成! 3.下载C ...

  8. 从0开始学习ssh之basedao

    用于所有dao里边会有许多相同的方法,例如save,update等等.应此设计一个basedao,所有dao都继承它.这样可以省去许多工作量. basedao如下 package cn.itcast. ...

  9. 从0开始学习ssh之资源分类

    更目录下面,新建config用于放配置文件,新建test用于放置测试文件.src目录用于放置源代码.由于ssh是三层,因此新建三层包(dao,service,view).其中dao和service还有 ...

随机推荐

  1. bootstrap-----流体布局解析

    流体布局容器 容器的width为auto,只是两边加了15px的padding. 流体布局容器 容器的width为auto,只是两边加了15px的padding. <div class=&quo ...

  2. 树莓派3B+ 人脸识别、摄像头安装和使用

    最近在学校里折腾树莓派上的人脸识别,折腾了很久才能用 在此记录下使用的过程和遇到的困难 过程基于超有趣!手把手教你使用树莓派实现实时人脸检测完成的.其中前面opencv的安装是文章中的Raspbian ...

  3. Eclipse注释快捷键、如何生成API以及可能遇到的问题解决

    1.Java注释方式单行注释// 快捷键:ctrl+/多行注释/* 快捷键:shift+ctrl+/*/文档注释/** 快捷键:shift+Alt+j */ 2.生成API文档 打开index.htm ...

  4. [JZOJ3320] 【BOI2013】文本编辑器

    题目 题目大意 给你一个文本,要删去其中所有的'e'. 有三种操作: h光标左移. x删除光标上面的字母(光标是横着的). fc跳到后面的第一个字符为'c'的位置. 问操作序列的最短长度. 思考历程 ...

  5. 线性dp——cf1012C好题

    比较套路的dp题 /* dp[i][j][0|1]:前i座山盖了j座房子,第i座不盖|盖 dp[i][j][0]=min( dp[i-1][j][0] , dp[i-1][j][1]+max(0,a[ ...

  6. LUOGU P1039 侦探推理 (字符串+模拟)

    传送门 解题思路 一道%你神题,\(string\)好强大啊..首先枚举一个周几,再枚举一个罪犯是谁,然后判断的时候就是枚举所有人说的话.定义\(fAKe[i]\)表示第\(i\)个人说的是真话还是假 ...

  7. RPC 编程

    我们从一个简单的 RPC "Hello, world!"的例子开始. 参考资料:MSDN: Win32 and COM Development -> Networking - ...

  8. mysql重点,表查询操作和多表查询

    表单查询 1. 完整的查询语句语法 select distinct(* or 字段名 or 四则运算 )from 表名 where 条件 group by 条件 having 条件 order by ...

  9. logback配置数据源日志error级别写入库

    LOGBACK.XML中配置 <appender name="db_log" class="ch.qos.logback.classic.db.DBAppender ...

  10. C++的注释

    ### 1.2 注释 **作用**:在代码中加一些说明和解释,方便自己或其他程序员程序员阅读代码 **两种格式** 1. **单行注释**:// 描述信息  - 通常放在一行代码的上方,或者一条语句的 ...