SSH框架环境配置

第一步:首先需要在myEclipse上创建一个web工程; 即在左侧package栏空白处右击newWeb Project

                                                 

第二步:引入需要的Jar

         struts2的解压路径下找到这些路径下的jar包。(直接把这些包复制,然后找到项目中的companyWebRootWEB-INFlib,点击lib位置Ctrl+V粘贴即可)

struts-2.3.15.3\apps\struts2-blank.war\WEB-INF\lib\*.jar

struts-2.3.15.3\lib\struts2-json-plugin-2.3.15.3.jar

struts-2.3.15.3\lib\struts2-spring-plugin-2.3.15.3.jar

       struts2的解压路径下找到struts.xml文件,放入companysrc文件下

 

       Spring的解压路径下找到这些路径下的jar同样放到companyWebRootWEB-INFlib

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

Springweb中使用

spring-web-3.2.0.RELEASE.jar

Spring整合Junit测试

spring-test-3.2.0.RELEASE.jar

 Spring的解压路径下找到applicationContext.xmllog4j.properties两个文件,放入companysrc文件下;


hibernate的解压路径下找到这些路径下的jar包(最后三个自己去网上查找),同样放到到companyWebRootWEB-INFlib

                  * hibernate-distribution-3.6.10.Final\hibernate3.jar——核心jar

*hibernate-distribution-3.6.10.Final\lib\required\*.jar

*hibernate-distribution-3.6.10.Final\lib\jpa\*.jar

* slf4j-log4j整合的jar :

*数据库驱动:

*连接池:(c3p0连接池)

                       

 

第三步:配置文件的编写

        companyWebRootWEB-INF下有一个文件是web.xml,接下来我们要配置核心过滤器和核心监听器。

         

<span style="font-size:18px;"><span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	
	 <!-- 配置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>
 
	 <!-- 配置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>
 	<dispatcher>REQUEST</dispatcher>
 	<dispatcher>FORWARD</dispatcher>
 </filter-mapping>

  <display-name></display-name>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
</span></span>

第四步:配置基本信息

     c3p0连接池:

               1.建立属性文件:找到companysrc,右击src文件newFile

                

         2、打开jdbc.properties,设置数据库驱动,数据库连接名称、用户和密码

<span style="font-size:18px;">jdbc.driver= com.mysql.jdbc.Driver
jdbc.url= jdbc:mysql:///company
jdbc.user= root
jdbc.password=123</span>


        3、在spring里面配置连接池、Hibernate的相关信息、配置Hibernate的映射文件、事务管理:

<span style="font-size:18px;"><?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:aop="http://www.springframework.org/schema/aop"
	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.xsd
	http://www.springframework.org/schema/aop
	http://www.springframework.org/schema/aop/spring-aop.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx.xsd">
	
	<!-- 配置连接池: -->
	<!-- 引入属性文件 -->
	<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的映射文件 -->
		<property name="mappingResources">
			<list>
				<value>cn/itcast/shop/user/vo/User.hbm.xml</value>
				<value>cn/itcast/shop/category/vo/Category.hbm.xml</value>
				<value>cn/itcast/shop/product/vo/Product.hbm.xml</value>
				<value>cn/itcast/shop/categorysecond/vo/CategorySecond.hbm.xml</value>
				<value>cn/itcast/shop/order/vo/Order.hbm.xml</value>
				<value>cn/itcast/shop/order/vo/OrderItem.hbm.xml</value>
				<value>cn/itcast/shop/adminuser/vo/AdminUser.hbm.xml</value>
			</list>
		</property>
	</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的配置  =============================-->
</beans>
</span>


这样整个SSH框架的环境变量就配置好了,接下来就可以正式敲写代码了!!!!!



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 22
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值