j2ee开发时的常见异常

启动tomcat时报如下异常(节选)
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
Caused by: java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V


hibernate和spring的包冲突。其中asm-2.2.2.jar与asm.jar存在类上的冲突!!!
解决办法是:
1.去掉类路径上的关于Hibernate的3个lib
asm.jar
asm-attrs.jar
cglib-2.1.3.jar

2.加入Spring中的以下4个lib
asm-2.2.2.jar
asm-commons-2.2.2.jar
asm-util-2.2.2.jar
cglib-nodep-2.1_3.jar


maven+ssh时,打开jsp页面,抛出如下异常:
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 22 in the generated java file
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
...


实际上也是包冲突。仔细检查工程里是不是加载了jsp-api.jar之类的。因为tomcat器已配置了这些基本的包,所以应将pom.xml中的依赖删除:
<!-- 
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.0</version>
			<scope>provided</scope>
		</dependency>
		 -->

重新编译,并重启tomcat就ok了

你可能感兴趣的:(java,spring,tomcat,jsp,Hibernate)