SSH项目整合---项目环境搭建

1 创建一个web工程

2 引入jar包 

 struts2 的jar包和配置文件 web.xml和struts.xml

web.xml <!--配置structs2的核心过滤器-->

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.rg.filter.strutsPrepareAndExceptionFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

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.devMode" value="false" />
</struts>
Spring jar包导入
配置文件 web.xml和applicationContext.xml
web.xml
<!-- 配置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>
applicationContext的位置默认是在WEB-INF/下的applicationContext.xml 需要指定位置

log4j.properties

Hibernate 1 jar包导入
      *hibernate3.jar lib equired*.jar jpajar
       *sl4j-log4j整合的jar包
       *数据库驱动 mysql-connector-java
       *C3p0连接池 c3p0-0.9.1.jar
配置文件:使用没有hibernate的核心配置文件的方式进行整合
映射文件

配置基本信息:
C3P0连接池: 引入外部属性文件:jdbc.properties
      配置C3p0连接池
事务管理
Hibernate相关信息
jdbc.driver = com.mysql.jdbc.Driver
jdbc.url = jdbc:mysql:///shop
jdbc.user = root
jdbc.password =*******
 
在Sprig中配置事务管理 相关信息 C3p0
<!-- 配置连接池: -->
<!-- 引入外部属性文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 配置C3P0连接池: -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</bean>

<!-- Hibernate的相关信息 -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 注入连接池 -->
<property name="dataSource" ref="dataSource"/>
<!-- 配置Hibernate的其他的属性 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
  <!-- 配置Hibernate的映射文件 -->
</bean>
<!-- 事务管理: -->
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 开启注解事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- Action的配置 ===========================-->
<!-- Service的配置  ===========================-->
<!-- Dao的配置  ===========================-->




 
原文地址:https://www.cnblogs.com/who-am-i/p/12080796.html