Struts2版本升级

@Struts2-2.3版本升级–>2.5.14.1

第一步 修改web.xml中配置

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

修改成

org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter

第二步 修改Struts.xml头部信息


修改为


第三步 替换jar包

因为我升级的项目是maven管理的,所以只需要在pom.xml文件移除和添加相关依赖关系,maven将会自动下载依赖包到仓库中.相关maven操作可以去查找
移除依赖包
下面是项目中移除的依赖关系


		    asm
		    asm
		    3.3
		
		
			log4j
			log4j
			1.2.17
		 
		
			commons-lang
			commons-lang
			2.3
		
		
		    commons-fileupload
		    commons-fileupload
		 
		
			org.apache.struts
			struts2-core
			2.3.16.3
			
				
					asm
					asm
				
			
		
		
			org.apache.struts
			struts2-convention-plugin
			2.3.16.3
		
		
			org.apache.struts
			struts2-rest-plugin
			2.3.16.3 
		
		
			org.apache.struts
			struts2-spring-plugin
			2.3.16.3
			
				
					org.springframework
					spring-beans
				
				
					org.springframework
					spring-core
				
				
					org.springframework
					spring-context
				
				
					org.springframework
					spring-web
				
				
					org.springframework
					spring-mock
				
				
					junit
					junit
				
			
		

替换及添加的依赖关系


		    org.freemarker
		    freemarker
		    2.3.27-incubating
		
		
		    org.apache.commons
		    commons-lang3
		    3.6
		
		
		    commons-lang
		    commons-lang
		    2.4
		
		
		    commons-fileupload
		    commons-fileupload
		    
		
		    org.javassist
		    javassist
		    3.20.0-GA
		
		
		    org.apache.logging.log4j
		    log4j-1.2-api
		    2.9.1
		
		
		    org.apache.logging.log4j
		    log4j-api
		    2.9.1
		
		
		    org.apache.logging.log4j
		    log4j-core
		    2.9.1
		
		
		    ognl
		    ognl
		    3.1.15
		
		
			org.apache.struts
			struts2-spring-plugin
			2.5.14.1
		
		
		    org.apache.struts
		    struts2-core
		    2.5.14.1
		
		
		    org.apache.struts
		    struts2-json-plugin
		    2.5.14.1
				
		
			org.apache.struts
			struts2-convention-plugin
			2.5.14.1
			
		
			org.apache.struts
			struts2-rest-plugin
			2.5.14.1
			

第四步 JSP页面中S标签调整

2.5版本以上 s标签有所调整


改成
 
      

改成
 
    
 
 改成

第五步 配置一个log4j2.xml

   
   
     
     
     
       
    
    
       
     


第六步 启动tomcat

启动之后,可能会爆一些相关错误.
我这里目前处理的错误
依赖包冲突错误 如下图就是明显的包冲突,去除多余依赖关系就OK
Struts2版本升级_第1张图片

此外2.5以上版本中 struts2-core核心包中有很多类路径做了调整
例如 我们项目中就有几个封装好的包,几经倒手,已经没有封装包的源码了,
其中大量方法extend了核心core中的StrutsResultSupport类
2.5之后该类路径做了调整
原–org.apache.struts2.dispatcher.StrutsResultSupport
现–org.apache.struts2.result.StrutsResultSupport
例如此类,解决方法
建立原同路径同包名类来extends现有类
或者
使用maven download Sources下载源码,在项目中创建原路径包名类,将源码内容copy过去.这样封装类中就调用你创建的.

使用通配符是找不到对应的action,需要设置:注意顺序

regex:.*,最好是全局设置:

此外 JDK版本必须在1.7以上

你可能感兴趣的:(struts2)