• 异常收集


    一些常见异常:

    //如果不用,启动时不会出错,但使用Dwr时,会抛出异常:java.lang.NoClassDefFoundError: antlr/ANTLRException  
    antlr-2.7.2.jar   
    //如果不用此包,在启动时会抛出: nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type  
    asm.jar  
    //如果不用此包,在启动时抛出:nested exception is java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException  
    aspectjweaver.jar  
    //如果不用此包,在启动时抛出:nested exception is java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter  
    cglib-2.1.3.jar  
    //如果不用此包,在启动时抛出:nested exception is java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap  
    commons-collections-3.1.jar  
    //这个似乎可以不用的
    commons-fileupload-1.2.1.jar  
    //这个就不用说啦,几乎所有框架都要使用的  
    commons-logging-1.0.4.jar   
    //如果不用此包会抛出:java.lang.NoClassDefFoundError: org/dom4j/DocumentException  
    dom4j-1.6.1.jar  
    //不用此包,在启动时报出:java.lang.NoClassDefFoundError: javax/transaction/TransactionManager jta.jar //struts2必须 freemarker-2.3.8.jar //struts2必须 ognl-2.6.11.jar //struts2核心包 struts2-core-2.0.11.2.jar //struts2整合Spring插件 struts2-spring-plugin-2.0.11.2.jar //struts2必须 xwork-2.0.5.jar

    启动异常:

    17:27:14,982 ERROR [STDERR] log4j:ERROR A "org.jboss.logging.appender.FileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
    17:27:14,983 ERROR [STDERR] log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
    17:27:14,983 ERROR [STDERR] log4j:ERROR [WebappClassLoader
    delegate: false
    repositories:
    /WEB-INF/classes/
    ----------> Parent Classloader:
    java.net.FactoryURLClassLoader@18ee2ee
    ] whereas object of type
    17:27:14,983 ERROR [STDERR] log4j:ERROR "org.jboss.logging.appender.FileAppender" was loaded by [org.jboss.system.server.NoAnnotationURLClassLoader@506411].
    17:27:14,983 ERROR [STDERR] log4j:ERROR Could not instantiate appender named "FILE".

    原因:项目Jar包与JBoss的jar包冲突(有关日志的jar包)。

    解决方法:删除项目中的有关日志的jar包。

    SEVERE: Exception fixing docBase for context [/cib]
    java.util.zip.ZipException: invalid END header (bad central directory offset) /oradata/mbp/tomcat6/apache-tomcat-6.0.24/webapps/cib.war
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:238)
    at java.util.jar.JarFile.<init>(JarFile.java:165)
    at java.util.jar.JarFile.<init>(JarFile.java:103)
    at sun.net.www.protocol.jar.URLJarFile.<init>(URLJarFile.java:71)
    at sun.net.www.protocol.jar.URLJarFile.getJarFile(URLJarFile.java:56)
    at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:99)
    at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:131)
    at sun.net.www.protocol.jar.JarURLConnection.getJarFile(JarURLConnection.java:98)
    at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:148)
    at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:882)
    at org.apache.catalina.startup.ContextConfig.init(ContextConfig.java:1017)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:279)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.StandardContext.init(StandardContext.java:5439)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4215)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:593)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:615)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Mar 22, 2012 9:10:12 AM org.apache.catalina.core.StandardContext resourcesStart
    SEVERE: Error starting static Resources
    java.lang.IllegalArgumentException: Invalid or unreadable WAR file : invalid END header (bad central directory offset) /mbp/tomcat6/apache-tomcat-6.0.24/webapps/cib.war
    at org.apache.naming.resources.WARDirContext.setDocBase(WARDirContext.java:135)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4086)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4255)
    at org.apache.catalina.core.ContainerBase.addChildInternal(Con

    出现情况:war项目放在Tomcat下Windows系统时启动正常,将war包ftp到AIX(或者Linux)下启动的时候出现此异常。

    原因:ftp上传文件的时候,默认是以ASCII上传,对war文件有影响,到AIX的Tomcat下就不能启动了。。。

    解决方法:将FTP的上传方式改为二进制上传。

     编译异常:

     The type org.springframework.dao.support.DaoSupport cannot be resolved. It is indirectly referenced from required .class files

    出现情况:Dao类继承DaoSupport类(e.g. SqlMapClientDaoSupport or HibernateDaoSupport)的时候,编译出错

    原因:Spring框架中此类的依赖库没有导入。

    解决方法:将org.springframework.transaction-3.1.0.RELEASE.jar导入即可。

    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [applicationContext.xml]

    Offending resource: class path resource [resources/spring/applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [resources/spring/applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor

    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)

    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)

    at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)

     解决方法:缺少aopalliance.jar包,倒入即可

     

    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/aop]

    Offending resource: class path resource [resources/spring/applicationContext.xml]

    原因:在xml中使用了 xmlns:aop="http://www.springframework.org/schema/aop" ,但是却没有倒入spring的aop.jar包

    java.lang.NoClassDefFoundError: org/aspectj/weaver/reflect/ReflectionWorld$ReflectionWorldException

    at java.lang.Class.getDeclaredMethods0(Native Method)

    at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)

    at java.lang.Class.getDeclaredMethods(Class.java:1791)

    缺少aspectjweaver.jar

     com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory).
     at com.opensymphony.xwork2.inject.ContainerImpl.addInjectorsForMembers(ContainerImpl.java:157)

    查询了半天,看网上有人碰到过,但是没有解决,于是分析代码进行查询原因,原因就是配置文件struts配置文件没有找到,于是想到了修改的配置,经过查询代码发现了这个问题,就是如果你要是修改了config,以后所有的配置只会读取配置的文件,所以struts-spring.jar等插件都采用的default的配置,所以会出错,故修改config的配置,把default的文件全部添加上,然后再添加上自己的配置文件,本来可以采用Dispatcher的DEFAULT_CONFIGURATION_PATHS然后添加自己的配置文件就可以,但是发现这个变量是private的,所有只能把里面的内容全部拷贝出来,所以这个地方的扩展自定义功能也是没有太大意义的。

      <param-name>config</param-name>
      <param-value>
            struts-default.xml,struts-plugin.xml,struts.xml
      </param-value>

     

    Caused by: java.lang.ClassNotFoundException: org.hibernate.annotations.common.reflection.ReflectionManager

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

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

    这个问题在使用新版本的hibernate包的时候容易出现,需要加入另外一个hibernate包hibernate-commons-annotations-4.0.1.Final.jar

    最好是把所有的hibernate中required文件夹下的包全部加进去就好了

     

    Caused by: java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)

     如上面所示,少了required文件夹与日志相关的jboss-logging.jar

     

    Unable to load configuration. - bean - jar:file:/F:/Web/homesite/jsp/struts/WEB-INF/lib/struts2-convention-plugin-2.1.6.jar!/struts-plugin.xml:30:119
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:190)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)

    此error是由于Struts2引起的。Struts2较早版本各个包之间的依赖性不强,用到的时候随时添加都可以。

    但是后面比较新的版本就不行了,必须把其必备包全部放在lib下面,否则就报上面的错误

     

    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(ContainerBuilder.java:207)

    at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)

    at com.opensymphony.xwork2.inject.ContainerBuilder$3.create(ContainerBuilder.java:93)

    at com.opensymphony.xwork2.inject.ContainerBuilder$7.call(ContainerBuilder.java:487)

    at com.opensymphony.xwork2.inject.ContainerBuilder$7.call(ContainerBuilder.java:484)

    at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)

    at com.opensymphony.xwork2.inject.ContainerBuilder.create(ContainerBuilder.java:484)

    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.createBootstrapContainer(DefaultConfiguration.java:252)

    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)

    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)

    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:380)

    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:424)

    Caused by: java.lang.reflect.InvocationTargetException

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:293)

    ... 33 more

     缺少javassist.jar

    严重: Exception starting filter struts2Config

    Unable to load configuration. - action - file:/WorkPlace/Site/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/imix/WEB-INF/classes/resources/struts/struts.xml:69:46

    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:437)

    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)

    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)

    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)

    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)

    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)

    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)

    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)

    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

    at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)

    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)

    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)

    at org.apache.catalina.core.StandardService.start(StandardService.java:525)

    at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)

    at org.apache.catalina.startup.Catalina.start(Catalina.java:595)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)

    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

    如果你的struts.xml和applicationContext.xml配置正确,依然出现此问题,就是缺少Struts所依赖的一些包文件(struts2-spring-plugin.jar, commons类库)

     

    javax.servlet.ServletException: Class org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter is not a Servlet
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    	java.lang.Thread.run(Unknown Source)

     出现此问题是因为将Struts的StrutsPrepareAndExecuteFilter配置成了<servlet>,正确配置为<filter>过滤器(该类是个Filter,不是Servlet)

     

     运行时异常

    Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to test.test.DaoImpl
    at test.test.T.main(T.java:25)

     出现此问题是因为使用JDK的代理(Proxy)时,没有使用接口或者返回时不是用接口强转的,例如以下代码:

    DaoImpl di = (DaoImpl)new DaoProxy().bind(new DaoImpl()); // 应该用DaoImpl的接口来强转(JDK自带的Proxy只能动态代理实现接口的类,如果需要代理无接口的类需要使用cglib动态代理)
    di.print();
    
    // 正确做法为:
    Dao di = (Dao)new DaoProxy().bind(new DaoImpl()); 
    di.print();

    Exception in thread "main" java.lang.IncompatibleClassChangeError: class net.sf.cglib.core.DebuggingClassWriter has interface org.objectweb.asm.ClassVisitor as super class
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at net.sf.cglib.core.DefaultGeneratorStrategy.getClassVisitor(DefaultGeneratorStrategy.java:30)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:24)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:144)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:116)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
    at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
    at test.test.DaoCglib.getInstance(DaoCglib.java:21)
    at test.test.T.main(T.java:27)

    版本冲突,报错java.lang.IncompatibleClassChangeError: class net.sf.cglib.core.DebuggingClassWriter has interface org.objectweb.asm.ClassVisitor as super class

    使用cglib 2.2 可解决此问题,该版本中的DebuggingClassWriter的父类为ClassWriter

     

    欢迎加入我的QQ群(JAVA开发):216672921,程序 元 世界
  • 相关阅读:
    最受欢迎的北大通选课导读·1[精品]
    社会保险,
    养老金的计算,
    毫秒 后的一个计算,
    返回格式 的数据结构再次改造,
    阶段状态池子,
    生活,-摘
    融合,
    tableview 也可以实现这个效果,
    字体大小 一致起来,
  • 原文地址:https://www.cnblogs.com/icerainsoft/p/2313482.html
Copyright © 2020-2023  润新知