zoukankan      html  css  js  c++  java
  • Spring总结及SSH配置的步骤

    1、  Spring的诞生

    为了解决大型企业级应用的结构复杂,涉及外部资源众多,事务密集、数据规模庞大,用户数量多,又较强的安全性考虑和较高的性能要求。------Rod Jonson (Spring的作者)

    2Spring的优化

    Spring属于集成框架,其核心基于控制反转(Inverse of Control IOC),Spring是一个全面的解决方案:提倡不重新造轮子。

    3、  Spring包含的模块

    Core AOPDAOORMJEEWEB

    4、  Spring的核心机制----依赖注入

    所谓的依赖注入就是当某个角色需要另一个角色的协助时,通常由调用者来创建被调用者的实例。在Spring中,创建者调用实例的工作常由Spring容器来完成,然后注入调用者。

    例如:在Action中需要使用Service的对象,我们可以通过注入来实现对象的引用。

    private UserService userService;

       publicvoid setUserService(UserService userService) {

          this.userService = userService;

       }

    5、  log4j的日志记录-----log4j.properties

    》》规范:

    #ootLogger是所有日志的根志,修改该日志属性将对所有日志起作用

    #有日志的输出级别info,输出源console

    #log4j.rootLogger=info,console

    #定义输出位置是控制台

    log4j.appender.console=org.apache.log4j.ConsoleAppender

    #日志布局采用的类

    log4j.appender.console.layout=org.apache.log4j.PatternLayout

    #日志输出布局

    log4j.appender.console.ConversionPattern= [%p]%d{yyyy-MM-dd

    HH:mm:ss}%m%l

    》》实用:

    log4j.rootLogger=DEBUG,console,file

     

    log4j.appender.console=org.apache.log4j.ConsoleAppender

    log4j.appender.console.layout=org.apache.log4j.PatternLayout

    log4j.appender.console.ConversionPattern= [%p]%d{yyyy-MM-ddHH:mm:ss}%m%l

     

    log4j.appender.file=org.apache.log4j.FileAppender

    log4j.appender.file.file=${log4j_root}/logs.file

    log4j.appender.file.layout=org.apache.log4j.PatternLayout

    log4j.appender.file.layout.ConversionPattern=[%p]%d{yyyy-MM-ddHH:mm:ss}%m%r%n

    6、  SSH整合

    1SSH框架的搭建

    步骤:

    1、添加集成好的所有Jar包。

    2、添加顺序Struts2Hibernate3Spring2.5Spring3.0

    3、分别编写配置web.xmlHibernatedao.xmlsrvice.xmlaction.xmlApplicationContent.xml

    Web.xml文件下的主要配置:

    <!-- 配置spring -->

       <context-param>

          <param-name>contextConfigLocation</param-name>

          <param-value>classpath:applicationContext.xml</param-value>

       </context-param>

       <listener>

          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

       </listener>

       <listener>

           <listener-class>com.accp.jboa.utils.Log4jListener</listener-class>

       </listener>

      

       <!-- 配置字符过滤器 -->

       <filter>

          <filter-name>characterFilter</filter-name>

          <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

          <init-param>

             <param-name>encoding</param-name>

             <param-value>UTF-8</param-value>

          </init-param>

       </filter>

     

       <!-- 配置OSIV过滤器 -->

        <filter>

           <filter-name>OSIVFilter</filter-name>

           <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>

        </filter>

       

        <!-- 配置Struts2 -->

       <filter>

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

          <filter-class>

             org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

       </filter>

    Hibernate.cfg.xml的配置:

    <session-factory>

          <property name="myeclipse.connection.profile">JBOA</property>

          <property name="dialect">

             org.hibernate.dialect.Oracle9Dialect

          </property>

          <property name="show_sql">true</property>

          <mapping resource="com/accp/jboa/entity/ClaimVoucher.hbm.xml" />

          <mapping resource="com/accp/jboa/entity/CheckResult.hbm.xml" />

          <mapping resource="com/accp/jboa/entity/Position.hbm.xml" />

          <mapping resource="com/accp/jboa/entity/Department.hbm.xml" />

          <mapping resource="com/accp/jboa/entity/ClaimVoucherDetail.hbm.xml" />

          <mapping resource="com/accp/jboa/entity/Employee.hbm.xml" />

     

       </session-factory>

    数据库访问属性文件:db.properties

    driver=oracle.jdbc.driver.OracleDriver

    url=jdbc:oracle:thin:@localhost:1521:orcl

    user=jboa

    password=jboa

    Config文件夹下的dao.xml配置:

    <!-- 配置数据源 -->

       <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

          <property name="driverClassName" value="${driver}"></property>

          <property name="url" value="${url}"></property>

          <property name="username" value="${user}"></property>

          <property name="password" value="${password}"></property>

       </bean>

        

       <!-- 配置session工厂 -->

       <bean id="sessionFactory"

          class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

          <property name="dataSource" ref="dataSource"></property>

          <property name="configLocation" value="classpath:hibernate.cfg.xml">

          </property>

       </bean>

     

       <!-- 配置dao基类 -->

       <bean id="baseDao" abstract="true" class="com.accp.jboa.dao.BaseDao">

          <property name="sessionFactory" ref="sessionFactory"></property>

       </bean>

     

       <!--********************以下为具体的****************** -->

     

       <bean id="claimVoucherDao" class="com.accp.jboa.dao.ClaimVoucherDao" parent="baseDao"></bean>

     

       <bean id="userDao" class="com.accp.jboa.dao.UserDao" parent="baseDao"></bean>

    Config文件夹下的Service.xml配置:

    xmlns:p="http://www.springframework.org/schema/p"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xmlns:aop="http://www.springframework.org/schema/aop"

       xsi:schemaLocation="

          http://www.springframework.org/schema/beans

          http://www.springframework.org/schema/beans/spring-beans-2.5.xsd

          http://www.springframework.org/schema/tx

          http://www.springframework.org/schema/tx/spring-tx-2.5.xsd

          http://www.springframework.org/schema/aop     

          http://www.springframework.org/schema/aop/spring-aop-2.5.xsd

       ">

      

       <!-- 事务配置 -->

       <bean id="txManager"

          class="org.springframework.orm.hibernate3.HibernateTransactionManager">

          <property name="sessionFactory" ref="sessionFactory"></property>

       </bean>

        <!-- Advice -->

       <tx:advice transaction-manager="txManager" id="serviceAdvice">

          <tx:attributes>

             <tx:method name="*" propagation="REQUIRED" />

             <tx:method name="get*" read-only="true" />

             <tx:method name="find*" read-only="true" />

          </tx:attributes>

       </tx:advice>

       <!-- AOP -->

       <aop:config>

          <aop:pointcut expression="execution(* com.accp.jboa.service..*.*(..))"

             id="serviceMethod" />

          <aop:advisor advice-ref="serviceAdvice" pointcut-ref="serviceMethod" />

       </aop:config>

     

       <aop:aspectj-autoproxy></aop:aspectj-autoproxy>

     

       <bean id="baseService" class="com.accp.jboa.service.BaseService" abstract="true"></bean>

     

     

       <bean id="claimVoucherService" class="com.accp.jboa.service.ClaimVoucherService" parent="baseService">

          <property name="claimVoucherDao" ref="claimVoucherDao"></property>

       </bean>

      

       <bean id="userService" class="com.accp.jboa.service.UserService" parent="baseService">

          <property name="userDao" ref="userDao"></property>

       </bean>

    Config文件夹下的action.xml配置:

    <!-- 分页bean -->

       <bean id="pageBean" class="com.accp.jboa.utils.PaginationSupport"

          scope="prototype"></bean>

      

       <!-- 基础action -->

       <bean id="baseAction" class="com.accp.jboa.action.BaseAction" abstract="true" scope="prototype">

          <property name="pageBean" ref="pageBean"></property>

       </bean>

     

       <bean id="claimVoucherAction" class="com.accp.jboa.action.ClaimVoucherAction" parent="baseAction" scope="prototype">

          <property name="claimVoucherService" ref="claimVoucherService"></property>

       </bean>

    Struts.xml下编写相应的action:

    <packagename="default"namespace="/"extends="struts-default">

          <actionname="user"class="userAction">

             <resultname="input">/login.jsp</result>

            

             <resultname="success">/success.jsp</result>

          </action>

  • 相关阅读:
    js代码中引入其他js文件
    SQL Server 创建跨库查詢、修改、增加、删除
    将SQL Server查询导出本地excel(mail发送)
    SQL Server2008 xp_cmdshell啟用
    SQL Server存储过程邮件发送以表格方式发送
    SQL Server2008进程堵塞处理方法
    sql 上舍下舍運用
    怎樣添加設置GridView,CheckBox全選功能
    点击 Button触发事件将GridView1 CheckBox勾选的行添加到GridView2中
    ES6-Proxy,代理
  • 原文地址:https://www.cnblogs.com/boonya/p/2161883.html
Copyright © 2011-2022 走看看