SSH笔记-注解开发(1)开发环境搭建




     1,表现层框架 Struts2:
 
 1)导包:
 apps\struts2-blank.war    存放struts2最基本的jar包(都要)
 struts2-convention-plugin-2.3.7.jar 用于struts使用注解
 struts2-json-plugin-2.3.7.jar   用于struts2整合Ajax
 struts2-spring-plugin-2.3.7.jar  用于struts2整合Spring
 
 2)在web.xml配置核心拦截器(Struts2.1.3开始使用StrutsPrepareAndExecuteFilter)
   <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>
 
 3)在src目录创建struts.xml (核心配置文件)
  ---约束  struts2-core-2.3.20.jar/struts-2.0.dtd
  ---常量设置  /org/apache/struts2/default.properties
 
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE struts PUBLIC
     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
     "http://struts.apache.org/dtds/struts-2.0.dtd">
 <struts>
    <constant name="struts.devMode" value="true" />  
    <package name="basicstruts2" extends="struts-default">
        <action name="index">
           <result>/index.jsp</result>
        </action>  
    </package> 
 </struts>

     2,业务层框架 Spring3.2

  1) jar包导入
       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框架 (整合hibernate )
      spring-orm-3.2.0.RELEASE.jar
            Spring在web中使用
       spring-web-3.2.0.RELEASE.jar
            Spring整合Junit测试
       spring-test-3.2.0.RELEASE.jar
 

   2) 在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>

 3) 在src下 创建applicationContext.xml
 <?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">
 
  <!-- 引入外部 properties 文件 -->
  <context:property-placeholder location="classpath:jdbc.properties"/>
 
  <!-- 数据库连接池  -->
  <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
   <property name="driverClass" value="${jdbc.driver}"></property>
   <property name="jdbcUrl" value="${jdbc.url}"></property>
   <property name="user" value="${jdbc.user}"></property>
   <property name="password" value="${jdbc.password}"></property>
  </bean>
  
  
  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  
   <!-- 引用数据库连接池 -->
   <property name="dataSource" ref="dataSource"></property>
  
   <!-- 配置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.hbm2ddl.auto">update</prop>
    </props>
   </property>
   
   <!-- 引用hbm 映射文件 -->
   <property name="mappingDirectoryLocations">
    <list>
     <!-- 引用目录,加载目录下所有 hbm 文件 -->
    <value>classpath:cn/.../domain</value>
    </list>
   </property>
  </bean>
 
  <!-- 事务管理器 -->
  <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
   <property name="sessionFactory" ref="sessionFactory"></property>
  </bean>
 
  <tx:annotation-driven transaction-manager="transactionManager"/>
 
 
 </beans>
   4) 在src下 创建log4j.properties


     3,持久层框架 hibernate3.6

  1) jar包导入
       hibernate3.jar
       required/*.jar
      hibernate-jpa-2.0-api-1.0.1.Final.jar
      c3p0 + mysql驱动
        整合log4j 导入slf4j 整合jar包 slf4j-log4j12-1.7.2.jar (因为spring已经导入 log4j 无需再次导入)
   二级缓存
       ehcache-1.5.0.jar
       commons-logging.jar
       backport-util-concurrent.jar

     2) 在src下 创建hibernate.cfg.xml
      ---可以不用写这个 
 
    3) 在PO类所在包 创建 类名.hbm.xml
      --使用Myeclipse关联数据库生成
 










  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值