Chinaunix首页 | 论坛 | 博客
  • 博客访问: 130798
  • 博文数量: 47
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 243
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-18 11:45
文章分类

全部博文(47)

文章存档

2017年(2)

2015年(33)

2014年(12)

分类: Java

2015-04-07 13:49:08

1.导入jar包
    struts
        必须jar
            struts2-core-2.3.14.jar   struts2框架核心类库
            xwork-core-2.3.14.jar    Command模式框架,WebWork和struts2都基于xwork
            ognl-3.0.6.jar   对象图导航语言,struts2框架通过其读写对象的属性
            freemarker-2.3.19.jar  struts2的UI标签的模板使用FreeMarker编写
            commons-fileupload-1.2.2.jar  文件上传组件
            commons-io.2.0.1.jar  传文件依赖的jar包
            commons-lang3-3.1.jar  对java.lang包的增强
            asm-3.3.jar  提供字节码的读写功能,包含核心功能,而其他的jar都是基于这个核心的扩展
            asm-commons-3.3.jar  提供了基于事件的表现形式
            asm-tree-3.3.jar  提供了基于对象的表现形式
            javassist-3.11.0.GA.jar  代码生成工具,struts2用它在运行时扩展Java类
            commons-logging-1.1.x.jar  ASF出品的日志包,struts2框架使用这个日志包支持log4j和jdk1.4的日志目录
       整合jar
            struts2-spring-plugin-2.3.14.jar   struts整合spring时导入
       struts注解开发jar
            struts2-convention-plugin-2.3.14.jar   如不使用注解开发,千万不导入此包
    spring
       必须jar
           基本开发:

    spring-beans-3.2.2.RELEASE.jar

    spring-context-3.2.2.RELEASE.jar

    spring-core-3.2.2.RELEASE.jar

    spring-expression-3.2.2.RELEASE.jar

    com.springsource.org.apache.commons.logging-1.1.1.jar

           web开发
               spring-web-3.2.2.RELEASE.jar
           junit测试:
               spring-test-3.2.2.RELEASE.jar
           AOP开发:   

    spring-aop-3.2.2.RELEASE.jar

    spring-aspects-3.2.2.RELEASE.jar

    com.springsource.org.aopalliance-1.0.0.jar

    com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar

           JDBC开发:   

    spring-jdbc-3.2.2.RELEASE.jar

    spring-tx-3.2.2.RELEASE.jar

       整合jar

     spring-orm-3.2.2.RELEASE.jar    ORM框架整合需要的包(hibernate)

    hibernate
       必须jar

hibernate3.jar   核心jar

antlr-2.7.6.jar,一个语言转换工具,Hibernate利用它实现 HQL SQL 的转换

commons-collections-3.1.jarcollections Apache 的工具集,用来增强Java对集合的处理能力

dom4j-1.6.1.jardom4j XML 解析器

javassist-3.12.0.GA.jar,代码生成工具, Hibernate用它在运行时扩展 Java

jta-1.1.jar,标准的 JAVA 事务(跨数据库)处理接口

slf4j-api-1.6.1.jarhibernate使用的日志框架

       注解jar

hibernate-jpa-2.0-api-1.0.1.Final.jarJPA 接口开发包

       整合log4j

slf4j-log4j12-1.7.5.jar

       ehcache

ehcache-1.5.0.jar

backport-util-concurrent-2.1.jar

commons-logging (spring已经提供)

    连接池与驱动
          C3P0

        com.springsource.com.mchange.v2.c3p0-0.9.1.2.jar

          DBCP

        com.springsource.org.apache.commons.dbcp-1.2.2.osgi.jar

        com.springsource.org.apache.commons.pool-1.5.3.jar

          驱动

        mysql-connector-java-5.1.22-bin.jar

2.web.xml

点击(此处)折叠或打开

  1. <!-- struts2 过滤器 -->
  2.     <filter>
  3.         <filter-name>struts2</filter-name>
  4.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  5.     </filter>

  6.     <filter-mapping>
  7.         <filter-name>struts2</filter-name>
  8.         <url-pattern>/*</url-pattern>
  9. </filter-mapping>
  10. <!-- 配置spring监听器,用于加载核心配置文件 -->
  11.     contextConfigLocation
  12.     classpath:applicationContext.xml

  13.     org.springframework.web.context.ContextLoaderListener

3.struts.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE struts PUBLIC
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
  4.     "">
  5. <struts>
  6.     <constant name="struts.devMode" value="true" />
  7.     <package name="ssh" namespace="/" extends="struts-default">
  8.         <!-- 配置用户Action -->
  9.         <action name="userAction_*" class="cn.itcast.ssh.web.action.UserAction" method="{1}">
  10.             <!-- 登录成功 -->
  11.             <result name="regist">/success.jsp</result>
  12.         </action>
  13.     </package>
  14. </struts>
3.spring容器

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns=""
  3.     xmlns:xsi=""
  4.     xsi:schemaLocation="
  5.                         /spring-beans.xsd">
  6.     <!-- 配置service -->
  7.     <bean id="userService" class="cn.itcast.ssh.service.UserService">
  8.         
  9.     </bean>
  10. </beans>
4.hbm.xml映射文件

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-mapping PUBLIC
  3.     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  4.     "">
  5. <hibernate-mapping package="cn.itcast.ssh.domain">
  6.     <class name="User" table="t_user">
  7.         <id name="id">
  8.             <generator class="native"></generator>
  9.         </id>
  10.         <property name="username"></property>
  11.         <property name="password"></property>
  12.     </class>
  13. </hibernate-mapping>
5.hibernate.cfg.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE hibernate-configuration PUBLIC
  3.     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  4.     "">
  5. <hibernate-configuration>
  6.     <session-factory>
  7.         <!-- 1 基本4项 -->
  8.         <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  9.         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test02</property>
  10.         <property name="hibernate.connection.username">root</property>
  11.         <property name="hibernate.connection.password">1234</property>
  12.         
  13.         <!-- 2 方言 -->
  14.         <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
  15.         <!-- 3 sql显示和格式化 -->
  16.         <property name="hibernate.show_sql">true</property>
  17.         <property name="hibernate.format_sql">true</property>
  18.         <!-- 4 自动创建表 -->
  19.         <property name="hibernate.hbm2ddl.auto">update</property>
  20.         <!-- 5 取消bean验证 -->
  21.         <property name="javax.persistence.validation.mode">none</property>
  22.         <!-- 6 线程绑定session -->
  23.         <property name="hibernate.current_session_context_class">thread</property>
  24.         
  25.         <!-- 添加映射文件 -->
  26.         <mapping resource="cn/itcast/ssh/domain/User.hbm.xml"/>
  27.     </session-factory>
  28. </hibernate-configuration>

6.XML整合
     applicationContext.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns=""
  3.        xmlns:xsi=""
  4.        xmlns:aop=""
  5.        xmlns:context=""
  6.        xmlns:tx=""
  7.        xsi:schemaLocation="
  8.                             /spring-beans.xsd
  9.                            
  10.                             /spring-tx.xsd
  11.                            
  12.                             /spring-aop.xsd
  13.                            
  14.                             /spring-context.xsd">
  15.     <!-- 配置sessionFactory -->
  16.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  17.         <property name="dataSource" ref="dataSource"></property>
  18.         <!-- 配置hibernate具体项 -->
  19.         <property name="hibernateProperties ">
  20.             <props>
  21.                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
  22.                 <prop key="hibernate.show_sql">true</prop>
  23.                 <prop key="hibernate.format_sql">true</prop>
  24.                 <prop key="hibernate.hbm2ddl.auto">update</prop>
  25.                 <prop key="javax.persistence.validation.mode">none</prop>
  26.                 <prop key="hibernate.current_session_context_class">thread</prop>
  27.             </props>
  28.         </property>
  29.         <!-- 配置映射文件位置
  30.             mappingLocations=classpath:cn/itcast/ssh/domain/User.hbm.xml 设置一个文件的位置
  31.             mappingLocations=classpath:cn/itcast/ssh/domain/*.hbm.xml 设置目录中的所有文件位置
  32.             mappingDirectoryLocations=classpath:cn/itcast/ssh/domain 设置一个目录
  33.         -->
  34.         <property name="mappingDirectoryLocations" value="classpath:cn/itcast/ssh/domain"></property>
  35.     </bean>
  36.     
  37.     <!-- 配置数据源dataSource -->
  38.     <context:property-placeholder location="classpath:jdbc.properties"/>
  39.     <!-- 数据源 -->
  40.     <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  41.         <property name="driverClassName" value="${driverClass}"></property>
  42.         <property name="url" value="${jdbcUrl}"></property>
  43.         <property name="username" value="${user}"></property>
  44.         <property name="password" value="${password}"></property>
  45.     </bean>
  46.     
  47.     <!-- 事务管理 -->
  48.     <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  49.         <property name="dataSource" ref="dataSource"></property>
  50.     </bean>
  51.     
  52.     <!-- 设置事务的通知 ,对切入点进行细化-->
  53.     <tx:advice id="txAdvice" transaction-manager="txManager">
  54.         <tx:attributes>
  55.             <tx:method name="regist" propagation="REQUIRED" isolation="DEFAULT" read-only="false"/>
  56.         </tx:attributes>
  57.     </tx:advice>
  58.     
  59.     <!-- 通过aop将切入点与通知进行管理 -->
  60.     <aop:config>
  61.         <aop:pointcut id="txPointcut" expression="execution(* cn.itcast.ssh.service.*.*(..))"/>
  62.         <!-- advisor 特殊的切面:一个通知,一个切入点 -->
  63.         <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
  64.     </aop:config>
  65. </beans>
  jdbc.properties

点击(此处)折叠或打开

  1. driverClass=com.mysql.jdbc.Driver
  2. jdbcUrl=jdbc:mysql://localhost:3306/test02
  3. user=root
  4. password=1234     
  applicationContext-*.xml

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns=""
  3.     xmlns:xsi=""
  4.     xsi:schemaLocation="
  5.         
  6.         /spring-beans.xsd
  7.         ">
  8.     <!-- Action -->
  9.         <bean id="userAction" class="com.usergoods.user.action.UserAction" scope="prototype">
  10.             <property name="userService" ref="userService"></property>
  11.         </bean>
  12.     <!-- service -->
  13.         <bean id="userService" class="com.usergoods.user.service.UserService">
  14.             <property name="userDao" ref="userDao"></property>
  15.         </bean>
  16.     <!-- Dao -->
  17.         <bean id="userDao" class="com.usergoods.user.dao.UserDao">
  18.             <property name="sessionFactory" ref="sessionFactory"></property>
  19.         </bean>
  20.     </beans>
     struts.xml     

点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE struts PUBLIC
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
  4.     "">
  5. <struts>
  6.     <constant name="struts.devMode" value="true" />
  7.     <package name="ssh" namespace="/" extends="struts-default">
  8.         <!-- 配置用户Action -->
  9.         <!-- class的值action使用
阅读(855) | 评论(0) | 转发(0) |
0

上一篇:spring事务

下一篇:ssh 注解整合

给主人留下些什么吧!~~