zoukankan      html  css  js  c++  java
  • struts1.3整合spring2.5(将spring委托给struts方式)

    前提是配置完struts1.3

    • 导包

      • spring-2.5.6.jar //spring核心包
      • spring-webmvc-struts-2.5.5.jar //struts整合spring使用
      • log4j-1.2.91.jar //log
      • img

    • spring配置

      • struts-config.xml
      <!--配置spring用的-->
      <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
      <!--配置spring 将spring委托给struts-->
      <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
          <set-property property="contextConfigLocation" value="/WEB-INF/config/applicationContext*.xml" />
      </plug-in>
      
      • applicationContext.xml
      <bean name="userManager" class="com.myframe.business.UserManager"></bean>
      <bean name="/User" class="com.myframe.struts.action.UserAction">
          <property name="userManager" ref="userManager"></property>
      </bean>
      
      • 创建一个UserManager类
      public class UserManager {
          public void run(){
              System.out.println("aaa");
          }
      }
      
      • Action中调用
      //spring需要创建的对象
      private UserManager userManager;
      public UserManager getUserManager() {
          return userManager;
      }
      public void setUserManager(UserManager userManager) {
          this.userManager = userManager;
      }
      //方法
      public ActionForward addUser(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
          userManager.run();
          return null;
      }
      

    • log4j的配置

      • 创建log4j.properties
      # For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!
      # For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
      log4j.rootLogger=info, stdout, logfile
      log4j.appender.stdout=org.apache.log4j.ConsoleAppender
      log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
      log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
      log4j.appender.logfile=org.apache.log4j.RollingFileAppender
      log4j.appender.logfile.File=${jadlstruts1spring2.root}/WEB-INF/myframe.log
      log4j.appender.logfile.MaxFileSize=100MB
      # Keep three backup files.
      log4j.appender.logfile.MaxBackupIndex=10
      # Pattern to output: date priority [category] - message
      log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
      log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
      
      • web.xml的配置
      <context-param>
          <param-name>log4jConfigLocation</param-name>
          <param-value>/WEB-INF/log4j.properties</param-value>
      </context-param>
       <listener>
          <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
      </listener>
      
  • 相关阅读:
    201-STM32+Air724UG基本控制篇(阿里云物联网平台)-设备使用物模型Topic上报温湿度数据
    Sentinel Go 核心统计结构滑动窗口的深度解析
    golang sync.Mutex互斥锁的实现原理
    Golang-Scheduler原理解析
    Golang-Channel原理解析
    golang里channel的实现原理
    最长回文子序列
    GO语言的goroutine并发原理和调度机制
    golang 常见问题
    通过js给网页加上水印背景
  • 原文地址:https://www.cnblogs.com/tonghaolang/p/7491144.html
Copyright © 2011-2022 走看看