ssh框架的搭建流程

来源:互联网 发布:python 盲水印 编辑:程序博客网 时间:2024/05/16 16:55

最后有惊喜!!!

1.先搭建struts2

1.1jar如下:


1.2在web.xml的struts2配置如下:

<!-- <<<<<<<<<<Struts2 配置 -->
<!-- Struts2的核心控制器-->
<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>
<!-- Stauts2 配置>>>>>>>>> -->

第一步:Struts的搭建就完成了。


2.接着进行Spring的搭建过程:

2.1.Spring的jar包


2.2在Struts2的struts.xml中整合Spring

<!-- 整合Spring -->
<constant name="struts.objectFactory" value="spring"></constant>
<package name="basicstruts2" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>

</package>

2.3在Struts2的web.xml中配置Spring

<!-- <<<<<<<<<<Spring 配置 -->
<!-- Spring核心监听器(注册spring监听器 ) -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- contextConfigLocation参数名称是系统默认解析的参数  -->

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- Spring 配置>>>>>>>>> -->

3.最后再进行Hibernate的搭建过程:

3.1jar包


3.2在Spring里配置Hibernate

<!--c3p0 数据源  -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 数据库连接信息 -->
<property name="driverClass" value="${driver}" />
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${user}" />
<property name="password" value="${password}" />
<!-- 数据库其他信息 -->
<!-- 指定数据库的初始化连接数 -->
<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>
<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="1800"></property>
<!-- 控制数据源内加载的PreparedStatements数量。
如果maxStatements与maxStatementsPerConnection均为0,
则缓存被关闭。Default: 0 
-->
<!-- C3P0缓存的Statement的数量 -->
<property name="maxStatements" value="8"></property>
<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
<property name="maxStatementsPerConnection" value="5"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<!-- JDBC数据源 -->
<property name="dataSource" ref="dataSource" />
<!-- 对于hibernate的配置 -->
<property name="hibernateProperties">
<props>
<!-- 指定数据库方言 -->
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<!-- 根据需要自动创建数据表 -->
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!-- 在控制台输出Hibernate生成的SQL语句 -->
<prop key="hibernate.show_sql">true</prop>
<!--  将SQL语句转换成格式良好的SQL语句-->
<prop key="hibernate.format_sql">true</prop>
<!--  -->
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
</props>
</property>
<property name="mappingResources">
<list>
<!-- 以下用来罗列出所有的PO映射文件,用xml配置的 -->
<value>com/test/domain/Person.hbm.xml</value>
</list>
</property>
<!-- 配置自动扫描,用注解配置 -->
<property name="packagesToScan">
<list>
<value>com.ssh.domain</value>
<value>com.test.domain</value>
</list>
</property>
</bean>

4.测试:junit


SSH的源代码下载地址是:

http://download.csdn.net/detail/qq_15340387/9075037

SSH的所需jar的下载地址是:

http://download.csdn.net/detail/qq_15340387/9075047


将mysql换成Oracle,需将jdbc.propertiesh和Spring的Hibernate的数据库方言换了,还需要加Oracle的驱动包,还有Oracle的主键生成也要注意换掉等等!!!


0 0
原创粉丝点击