非常SB的struts2.x异常(上篇)

学习struts2.2.1遭遇滑铁卢~~~~~好多异常~~~~~好多bug~~~~好多问题~~~~~~好多困难~~~好多肥羊~~~

一、

Filter mapping specifies an unknown filter name ----filter标签在web.xml里的顺序
   <filter-mapping>
        <filter-name>adminOperateLogFilter</filter-name>
        <url-pattern>/*</url-pattern>
   </filter-mapping>
   <filter>
        <filter-name>adminOperateLogFilter</filter-name>
        <filter-class>com.berheley.exam.web.filter.AdminOperateLogFilter</filter-class>
    </filter>
这样写启动服务器时报错 Filter mapping specifies an unknown filter name

adminOperateLogFilter

将这两块换个顺序就没问题了,web.xml信息的加载是有顺序的,filter在mapping之前必须要让服务

器找到其定义。

   <filter>
        <filter-name>adminOperateLogFilter</filter-name>
        <filter-class>com.berheley.exam.web.filter.AdminOperateLogFilter</filter-class>
    </filter>
   <filter-mapping>
        <filter-name>adminOperateLogFilter</filter-name>
        <url-pattern>/*</url-pattern>
   </filter-mapping>

二、

java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name

Struts2

答:“Struts2”?大写的?are you sure?我猜你一定是看了某struts2.0的权威指南(那是一个

chm文件电子书,而且你看的可能是翻译成中文的),我不知道英文版的有没有写错,但是我检查了

很久后才发现中文版存在这个大小写错误。

让我们看看我们复制的内容:

<!-- 定义Struts 2的FilterDispatcher的Filter -->

                                  <filter>

                                    <!-- 定义核心Filter的名字 -->

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

                                    <!-- 定义核心Filter的实现类 -->

                                  <filter-

class>org.apache.Struts2.dispatcher.FilterDispatcher

                                        </ filter-class>

                                  </filter>

                                 <!-- FilterDispatcher用来初始化Struts 2并且处理所有的

Web请求 -->

                                  <filter-mapping>

                                  <filter-name>Struts2</filter-name>

                                  <url-pattern>/*</url-pattern>

                                  </filter-mapping>

显然,上下两个filter-name不一致!改正它!

三、

java.lang.ClassNotFoundException: org.apache.Struts2.dispatcher.FilterDispatcher异常错误

?

答:“Struts2”?大写?OK,很明显,我们又复制了错误内容了,包名怎么会是大写呢?改正它!

四、顺便附上一些有用的内容:

Deployment Error Messages
FAIL - Application already exists at path /myNewApp If this message appears, the 
/myNewApp application has already been deployed. This may have happened because of

Tomcat's autoDeployfeature, or because you have already deployed the application

yourself.

The application will be listed in Applications list.

FAIL - Invalid context path myNewApp was specified This can happen if you forget the

leading slash on the application name (myNewApp instead of /myNewApp), or if the folder

does not exist.

Check the folder, especially capitilisation of any letters.

FAIL - Failed to deploy application at context path /myNewApp This typically indicates

an error in your web.xmlfile. Check the Tomcat logs to see more information about the

error.


参考网址:http://wiki.metawerx.net/wiki/TroubleshootingApplicationDeploymentOnTomcat


五、
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException异常?!!
注意到这句话:Caused by: java.lang.IllegalArgumentException: Javassist library is

missing in classpath! Please add missed dependency!

答:经过findjar查询需要加入javassist.jar包,一般这个包在struts2.2.1包下的apps\struts2-

blank-2.2.1的web-inf下的lib中。提示:war文件可以用rar解压!

2010-9-24 23:59:30 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Dispatcher initialization failed
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject

(ContainerImpl.java:295)
        at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct

(ContainerImpl.java:431)
        at com.opensymphony.xwork2.inject.ContainerBuilder$5.create

省略若干行……

(ContainerImpl.java:293)
        ... 41 more
Caused by: java.lang.ExceptionInInitializerError
        at com.opensymphony.xwork2.ognl.OgnlValueStackFactory.setContainer

(OgnlValueStackFactory.java:85)
        ... 46 more
Caused by: java.lang.IllegalArgumentException: Javassist library is missing in

classpath! Please add missed dependency!
        at ognl.OgnlRuntime.<clinit>(OgnlRuntime.java:165)
        ... 47 more
Caused by: java.lang.ClassNotFoundException: javassist.ClassPool
        at org.apache.catalina.loader.WebappClassLoader.loadClass

(WebappClassLoader.java:1360)
        at org.apache.catalina.loader.WebappClassLoader.loadClass

(WebappClassLoader.java:1206)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at ognl.OgnlRuntime.<clinit>(OgnlRuntime.java:162)
        ... 47 more

六、

2010-9-25 0:23:06 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
Class: com.opensymphony.xwork2.spring.SpringObjectFactory
File: SpringObjectFactory.java
Method: getClassInstance
Line: 220 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:220:-1
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428)
        at org.apache.struts2.dispatcher.FilterDispatcher.init

省略若干行…………

(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: java.lang.NullPointerException
        at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance

(SpringObjectFactory.java:220)
        at

com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType

(XmlConfigurationProvider.java:530)
        at

com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addResultTypes

(XmlConfigurationProvider.java:501)
        at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage

省略若干行…………

(Dispatcher.java:371)
        at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
        ... 28 more


#1楼 得分:0回复于:2010-05-30 13:53:17空指针捏, LZ集成struts2和spring的时候出问题了.?

有没有加struts2-spring-plugin的包?

答:经检查此方法不可行,因为这个项目只是使用struts2.2.1,并没有与spring整合。

网上有人提到:
“解决方法:
1.lib中多导入包的大原因,去掉struts2-spring-plugin-2.1.8包即可,因为在项目中没有用到

spring。
2.还有的项目中用到spring,在web.xml中却没配置监听器,所以在web.xml里面加上
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

答:同上。


我无奈之下,想到应该看看,里面的例子是怎么做的,于是打开F:\struts2-2.2.1-all\struts-

2.2.1\apps中的例子,查看它们的web.xml.
发现: 
<filter-class>      

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

但是问题没有解决。


我又参照网上的说法:把struts2-spring-plugin包放了回去(之前听信他们说什么不能加太多包,

于是只加了必要的包,如今又把这个包放了回去,但是个人认为这些异常不应该是由“加太多包”引

起的,因为这样好像不合逻辑。)


无奈中又留意到了下面的话:

严重: ********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********
Looks like the Spring listener was not configured for your web app! 
Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.
You might need to add the following to web.xml: 
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener

-class>
    </listener>
于是加了listener进去。


出现了新的提示:
java.io.FileNotFoundException: Could not open ServletContext resource
(感觉像在做推理 = =!)

Could not open ServletContext resource [/WEB-INF/applicationContext.xml] 
错误如下: 
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML

document from resource [/WEB-INF/applicationContext.xml] of ServletContext; nested

exception is java.io.FileNotFoundException: Could not open resource [/WEB-

INF/applicationContext.xml] of ServletContext 
java.io.FileNotFoundException: Could not open resource [/WEB-INF/applicationContext.xml]

of ServletContext

加载spring的配置文件时在默认位置/WEB-INF/下找不到applicationContext.xml文件,看了下,

myeclipse自动生成的applicationContext.xml放在/WEB-INF/classes下,难怪找不到,终于发现问

题了,下面在web.xml中做如下配置即可解决:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/classes/applicationContext.xml</param-value> 
</context-param>

((例子中的配置好像跟实际遇到的问题不一致?))
exception is java.io.FileNotFoundException: Could not open ServletContext resource
建个新的applicationContext.xml?
尝试建一个!
放在web-inf下面。

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

-class>
    </listener>


applicationContent.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springwork.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<context:annotation-config />
<context:component-scan base-package="com.service*" />
</beans>


Caused by: org.xml.sax.SAXParseException: Premature end of file applicationContext.xml
实在看不下去了,在网上搜了搜,发现解答已经扯远了。
正想放弃,换用myeclipse时,开始准备复制内容转移,忽然发现</beans>写成了</beans>>。
难道是因为这个?
果然重新运行后,发现“</beans>”标签,写多一个“>”都不可以!
(好像拿个砖头拍死自己-_-!)


问题还没完呢?
下面又来了新东西:

严重: Actual exception
Could not load class org.apache.struts2.jsf.ProcessValidationsInterceptor. Perhaps it

exists but certain dependencies are not available? - interceptor -

jar:file:/F:/netbeans%20workspace/netbeans%206.9/testStruts2/build/web/WEB-

INF/lib/struts2-jsf-plugin-2.2.1.jar!/struts-plugin.xml:38:108
        at com.opensymphony.xwork2.ObjectFactory.buildInterceptor

(ObjectFactory.java:213)
Caused by: java.lang.NoClassDefFoundError: javax/faces/context/FacesContext
Caused by: java.lang.ClassNotFoundException: javax.faces.context.FacesContext

在网上查到了一篇文章:

“““

当你的工程放了struts2.0.11/lib下的所有jars但没放log4j.jar会如何?

     我们总是需要开始,总是需要尝试,总是不断地去发现,去改进!
     我只是想让struts2跑起来,很低的要求,我大约用了4个晚上的时间,菜,好菜!好多波折啊

,好多辛酸!
     这是一篇写给超级才鸟的文章,因此坚决不会发到论坛里去!
     其实发到论坛里的动机很单纯,一个是容易被更多人看到,一个是升级为能投票的会员,行使

人间的正义权利!但此篇仅仅发表在blog里,如果某天有人遇到的这样的情况(可能性很小的),可

以翻阅此文!
        首先,下载struts2,地址为:http://struts.apache.org/,这里看到的是2.0.11GA,就用这

个版本!
         随便在硬盘上找个地方建立ROOT /WEB-INF/,classes和lib目录,当然可以在ROOT下建立个

index.htm什么的文件,欢迎一下!好,开始动手了,把struts2.0.11/lib下面的jar包都拷贝到

ROOT/WEB-INF/lib目录里,都拷贝进去!这还不够,再找点spring的文件,把spring/的常用的那几

个jar也拷贝到lib目录去,包括:spring.jar,spring-aop.jar,spring-beans.jar,spring-

context.jar,spring-core.jar,spring-mock.jar,spring-support.jar,spring-web.jar;然后

在ROOT/WEB-INF/ 下建立web.xml文件,内容如下:

xml 代码

<?xml version="1.0" encoding="UTF-8"?>   
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web

-app_2_4.xsd">   
   
    <display-name>Struts Blank</display-name>   
    <context-param>   
        <param-name>contextConfigLocation</param-name>   
        <param-value>   
            /WEB-INF/classes/applicationContext-*.xml   
        </param-value>   
    </context-param>   
    <listener>   
        <listener-class>   
            org.springframework.web.context.ContextLoaderListener   
        </listener-class>   
    </listener>   
    <filter>   
        <filter-name>struts2</filter-name>   
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>   
    </filter>   
   
    <filter-mapping>   
        <filter-name>struts2</filter-name>   
        <url-pattern>/*</url-pattern>   
    </filter-mapping>   
   
    <welcome-file-list>   
        <welcome-file>index.html</welcome-file>   
    </welcome-file-list>   
   
</web-app>   
然后到ROOT/WEB-INF/classes/下建立struts.xml文件,内容如下:

xml 代码

<?xml version="1.0" encoding="UTF-8" ?>   
<!DOCTYPE struts PUBLIC   
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
    "http://struts.apache.org/dtds/struts-2.0.dtd">   
   
<struts>   
   
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />   
    <constant name="struts.devMode" value="false" />   
   
   
    <!-- Add packages here -->   
   
</struts>   
ok,工作做完了,接下来把此目录部署到tomcat里成一个站点,补充一下:tomcat用5.5.25,jdk用

5.0.
好了,你可以启动你的tomcat了,启动tomcat,看tomcat/logs/catalina.2007-12-03.log,当然是你

运行时的日期,呵呵!
发现了什么,我想你一定会发现以下的错误:
Actual exception
Could not load class org.apache.struts2.jsf.FacesSetupInterceptor. Perhaps it exists but

certain dependencies are not available? - interceptor -

jar:file:/D:/website/MedicalChina/ROOT/WEB-INF/lib/struts2-jsf-plugin-

2.0.11.jar!/struts-plugin.xml:36:97
..............................................
Caused by: java.lang.NoClassDefFoundError: javax/faces/lifecycle/Lifecycle(这句很重要,

重要个屁,这句一点用也没有)
,貌似缺少jar包,但不知道缺少哪一个,呵呵!

在下经过详细的考证,发现缺少的是log4j.jar,呵呵,你再把log4j.jar放到lib里,重起tomcat就

一切正常了!
很简单吧,是简单,但你能从包错信息“Caused by: java.lang.NoClassDefFoundError:

javax/faces/lifecycle/Lifecycle”想到缺少的是log4j.jar这个包吗?我花了n个小时才明白了这

个事情!

      所以,我把它记录下来,供以后查阅,更供大家参考!

       赶兴趣的,可以去查源码,看为啥如此,呵呵!

”””


log4j为何这名字这么眼熟?忽然想起了前段时间使用hibernate3.5.5时也要弄这个包,而当时它的

final文件夹内缺了两个包:log4j-1.2.13.jar、slf4j-log4j12-1.5.2.jar,估计版本号影响不是很

大。

而这次我把上次的log4j包导入项目中,看看效果如何?提示:文章中说到了导入太多包会出现这个

问题,但是我只导入了必要的包。

又出新问题了:

org.apache.catalina.core.StandardContext filterStart 
严重: Exception starting filter struts2 
Class: com.opensymphony.xwork2.spring.SpringObjectFactory 
File: SpringObjectFactory.java 
Method: getClassInstance

Caused by: java.lang.NullPointerException 
at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance

(SpringObjectFactory.java:209) 
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyResultType


又参见了一篇文章:
“““

at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance

(SpringObjectFactory.java:2092010-07-19 18:27启动服务器时出现异常:

警告: Failed startup of context

{/,E:\workspace\uploadPhoto\war}

Class: com.opensymphony.xwork2.spring.SpringObjectFactory
File: SpringObjectFactory.java
Method: getClassInstance
Line: 209 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:209:-1
Caused by: java.lang.NullPointerException at

com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance

(SpringObjectFactory.java:209)

原因两个:
1.lib中多导入包的大原因:去掉struts2-spring-plugin-2.1.8包即可,因为没有用到spring。
2.还有的原因是用spring了,却没加监听器,在web.xml里面加上
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

”””

之前我是看了一些文章:加上了struts2-spring-plugin包的,而且还加上了
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> 
难道做错了???????

我把上面的删去了,但是还是有错。

(文章太长了,请接着看下一篇)嘿嘿~~~~~

= 。=

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值