SSH网上商城2_环境配置

来源:互联网 发布:淘宝商品视频内存大小 编辑:程序博客网 时间:2024/05/22 05:49

进入ssh框架的环境配置(myeclipse)笔记

  1. 新建一个web project:取名ltt_shop,其他保持不变
  2. 引入三大框架所要用到的所有包,放置在../WebRoot/WEB-INF/lib的目录下,jar包附在后面的网盘中
  3. 在../WebRoot/WEB-INF/下新建一个xml文件,在File Name行修改xml文件名,在Template to use 行选择第2行
    这里写图片描述
  4. 删掉其他还没用到的信息,留下以下内容
    <?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"
    <display-name></display-name>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>
  5. 进行Struts的配置
    在web xml 加入struts的核心过滤器配置,并在src目录下加入struts.xml, 将constant的value改成false
 <constant name="struts.devMode" value="false" />
 <!-- 配置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>

6.进行spring的配置
在web.xml加入Spring的核心监听器,并在src加入applicationContext.xml和log4j.properties

<!-- 配置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>

7.配置基本信息
在applicationContext.xml中加入以下信息

<!-- 配置连接池: -->    <!-- 引入外部属性文件 -->    <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>            </list>        </property>    </bean>    <!-- 事务管理: -->    <!-- 事务管理器 -->    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">        <property name="sessionFactory" ref="sessionFactory"/>    </bean>    <!-- 开启注解事务 -->    <tx:annotation-driven transaction-manager="transactionManager"/>

修改jdbc.properties的数据库名称和数据库密码

jdbc.driver = com.mysql.jdbc.Driverjdbc.url = jdbc:mysql:///shopjdbc.user = rootjdbc.password =081400abc

附下jar包和配置文件的链接
链接:https://pan.baidu.com/s/1c4R67W 密码:jix6