ssh 找不到 action

引用:http://blog.csdn.net/FastThinking/article/details/4060813

  这个困扰我已久的问题终于解决了,让我又一次坚信是问题总有办法解决的,没有什么奇奇怪怪的问题,特别是在编程方面,出

问题了总有原因,你找不到原因所在并不等于没有原因. 
        记得在几个月前就想好好学习一下struts,spring和hibernate,也就是我们常说的SSH,但是因为一个异常始终没有得到解决,

也使我暂时放下了对SSH的深入学习,而这个异常就是这篇日志要主要讲到的. 
        我用的开发工具Myeclipse6.0,在做struts1.2整合spring2.0时,用spring代理action,没有任何问题;做过struts1.2整合

hibernate3.0时也没有遇到问题;但就是在做SSH三者整合的时候出现问题了.我用ssh做了个简单的用户注册的例子,当请求action的

时候,页面报"Http 404 Servlet action is not available ",但是后台没有任何异常信息;这种错误往往是最难以解决的.于是通过

google搜索,发现许多ssh初学者都遇到过同样的问题,也有不少人因此放弃了对SSH的学习;当然网上也有不少的解决方案,这些解决方

案我把它归为两类: 
        第一种是说一定是配置文件出错,说要仔细查看struts和spring的配置文件,因为404很容易就让人想到"没有找到(not

found)" . 
        第二种是说在ssh三者整合时,容易发生jar冲突,主要是spring和hibernate共用的一些jar 文件发生冲突. 
        我反复查对过书本上的实例,在网上也看过不少网友发的SSH整合实例,我坚信struts和spring配置文件是没有问题的,所有我

觉得问题应该和第二种类似,jar包冲突.网上很多朋友都说删除"asm-2.2.3.jar"就OK了,但是删除后发现问题依旧,再加上除了404外,

后台也没有任何异常信息,这也是几个月前我暂时停止学习ssh的原因吧. 
        这也得益于经验的积累,才有今天此问题的解决.虽然在公司几个月期间,大都是直接用JSP开发,没有用到SSH,但经常维护一

些SSH做的项目,又基本天天都少不了看tomcat的logs,这也使我意识到了日志的重要性. 
        周末了,也让我有时间又有了再一次学习SSH的想法.在网上找了个视频的SSH整合实例讲解,一边听一边跟着做,很快就完成了

一个最简单的注册实例,可是在运行的时候,头疼的问题又来了,几个月不见的老朋友又回来了---"http 404 Servlet action is not

available",重复了以前的google搜索,问题还是没能得以解决.这时我想到了一个重要的工具:log4j 
        在项目的src目录下建立了一个log4j.properties文件,加入以下内容: 
log4j.rootLogger=info,A1 
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender 
log4j.appender.A1.Append=true 
log4j.appender.A1.File=D:/log4j.log 
log4j.appender.A1.DatePattern = '.'yyyy-MM-dd'.log' 
log4j.appender.A1.layout=org.apache.log4j.PatternLayout 
log4j.appender.A1.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss} Method:  %l%n%m%n 
其中D:/log4j.log是日志文件所在目录. 
保存好后重启tomcat,这时你会发现,虽然在控制台没有任何异常信息,但是在日志log4j.log中却可以看到错误所在,会发现有如下异

常信息: 
[ERROR] 2009-01-11 22:33:23 Method:  org.springframework.web.struts.ContextLoaderPlugIn.init

(ContextLoaderPlugIn.java:229) 
Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in

ServletContext resource [/WEB-INF/springContext.xml]: Invocation of init method failed; nested exception is

java.lang.SecurityException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does not

match signer information of other classes in the same package 
Caused by: 
java.lang.SecurityException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does not

match signer information of other classes in the same package

[ERROR] 2009-01-11 22:33:23 Method:  org.apache.catalina.core.ApplicationContext.log(ApplicationContext.java:676) 
action: null 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in

ServletContext resource [/WEB-INF/springContext.xml]: Invocation of init method failed; nested exception is

java.lang.SecurityException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does not

match signer information of other classes in the same package 
Caused by: 
java.lang.SecurityException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does not

match signer information of other classes in the same package 
有了异常信息就好办多了,google一下,很快就找到了原因和解决办法,主要是因为myeclipse为项目自动加入的commons-

beanutils.jar和commons-collections.jar相冲突,还有asm-2.2.3.jar ,解决方法主要有以下二点: 
    1.删除myeclispe自动加入的asm-2.2.3.jar 
    2.去www.apache.org官方网下载commons-beanutils-1.8.0.jar文件,替换myeclispe自动加入的commons-beanutils.jar包 
    重新部署,启动tomcat后,会发现日志的最后一行信息为: 
ContextLoaderPlugIn for Struts ActionServlet 'action', module '': initialization completed in 9765 ms 
好了,这说明问题已经解决了,测试一下,果然运行正常,没有问题了. 
        希望本日志能帮助出现同样问题的朋友,最后提醒一句:为项目加入日志是非常有帮助的,能够便于你测试及监测系统运行的

状态,感谢log4j,是它帮我解决了这困扰我已久的问题.

原文地址:https://www.cnblogs.com/sode/p/2591570.html