首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

struts2.1.6+hibernate3.3+spring3.0遇到的有关问题

2013-09-11 
struts2.1.6+hibernate3.3+spring3.0遇到的问题struts2.1.6+hibernate3.3+spring3.0遇到的问题首先进行单

struts2.1.6+hibernate3.3+spring3.0遇到的问题

struts2.1.6+hibernate3.3+spring3.0遇到的问题
首先进行单元测试:出现问题

?

package com.zzc.junit;import java.util.List;import javax.annotation.Resource;import org.junit.Test;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;import org.springframework.transaction.annotation.Transactional;import com.zzc.dao.SqlServerDao;@ContextConfiguration("classpath:applicationContext.xml")public class Test1 extends AbstractJUnit4SpringContextTests {SqlServerDao sqlServerDAO;@Testpublic void query() {List<String> list = sqlServerDAO.query();for(String s : list) {System.out.println(s);}}public SqlServerDao getSqlServerDAO() {return sqlServerDAO;}@Resource(name="sqlServerDao")public void setSqlServerDAO(SqlServerDao sqlServerDAO) {this.sqlServerDAO = sqlServerDAO;}}

?

问题1:
Caused by: java.lang.NoClassDefFoundError: org/junit/runners/BlockJUnit4ClassRunner
上网查看了下,原来是junit的jar包版本问题,spring2.5.6配搭junit4.4是没有问题的,但是spring3.0配搭junit4.4,使用了

@ContextConfiguration等spring3.0新的annotation就会有问题,将junit4.4改为junit4.82版本,问题解决。

?

问题2:
org/aopalliance/intercept/MethodInterceptor
Spring3.0 运行问题

报的错误是:java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor

上网查了下,这可能是spring3.0特有的问题,2.5就没有!出错的原因是少了个包,解决的方案是去

http://sourceforge.net/projects/aopalliance/files/下载aopalliance-alpha1.jar,加到路径里,就行了!

spring3.0比2.5需要好多额外的包,除了上面的aopalliance外,还可能会需要asm和cglib!

下载加入了aopalliance-alpha1.jar,进行测试,再次抛出异常:

?

问题3:

Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class

[org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator]: Constructor threw exception; nested

exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

Caused by: java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice

上网查看,发现又少了 com.springsource.org.aopalliance-1.0.0.jar 的jar包

到http://grepcode.com/snapshot/repository.springsource.com/org.aopalliance/com.springsource.org.aopalliance/1.0.0页面下载

com.springsource.org.aopalliance-1.0.0.jar
下载地址:

http://repository.springsource.com/ivy/bundles/external/org.aopalliance/com.springsource.org.aopalliance/1.0.0/com.springsour

ce.org.aopalliance-1.0.0.jar

?

问题4:

再次进行测试,又出现了新的问题:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlServerDao' defined in

file [E:\dormitory\Dormitory\WebRoot\WEB-INF\classes\com\zzc\dao\impl\SqlServerDaoImpl.class]: Initialization of bean failed;

nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named

'org.springframework.transaction.interceptor.TransactionInterceptor#0' must be of type [org.aopalliance.aop.Advice], but was

actually of type [org.springframework.transaction.interceptor.TransactionInterceptor]

Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named

'org.springframework.transaction.interceptor.TransactionInterceptor#0' must be of type [org.aopalliance.aop.Advice], but was

actually of type [org.springframework.transaction.interceptor.TransactionInterceptor]

?

解决方案:

? 将applicationContext.xml中的<tx:annotation-driven transaction-manager="transactionManager" />这一行注释掉

? 再运行,通过了。 但存在的问题是 事务不能工作了。

再解决:

TransactionInterceptor是 org.aopalliance.aop.Advice 的一个实现,可能是Jar包的冲突。

到jar包中去查看。

?我的问题是: aopalliance-1.0.jar 和 aopalliance-alpha1.jar之间的冲突。

?将aopalliance-alpha1.jar去掉,再运行就OK了。

?

问题5:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlServerDao' defined in

file [E:\dormitory\Dormitory\WebRoot\WEB-INF\classes\com\zzc\dao\impl\SqlServerDaoImpl.class]: BeanPostProcessor before

instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Aspect

Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/annotation/Aspect

加入aspectjrt.jar和aspectjweaver.jar,问题解决

?

问题6:
Caused by: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class

[com.mchange.v2.c3p0.ComboPooledDataSource] for bean with name 'sqlServerDataSource' defined in class path resource

[applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource

Caused by: java.lang.ClassNotFoundException: com.mchange.v2.c3p0.ComboPooledDataSource


一看知道,少了c3p0的jar,因为我使用了c3p0的数据源

<bean id="mysqlDataSource" destroy-method="close"> <property name="driverClass" value="org.gjt.mm.mysql.Driver"/><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/dormitory?useUnicode=true&amp;characterEncoding=UTF-8"/><property name="user" value="root"/><property name="password" value="123456"/><!--初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 --><property name="initialPoolSize" value="3"/><!-- 连接池中保留的最小连接数。 --><property name="minPoolSize" value="1"/><!-- 连接池中保留的最大连接数。Default: 15 --><property name="maxPoolSize" value="300"/><!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 --><property name="maxIdleTime" value="60"/><!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 --><property name="acquireIncrement" value="5"/><!-- 每60秒检查所有连接池中的空闲连接。Default: 0 --><property name="idleConnectionTestPeriod" value="60"/></bean>

?

加入c3p0-0.9.1.2.jar,问题解决

?


我的异常网推荐解决方案:org.springframework.beans.factory.BeanCreationException:,http://www.myexception.cn/j2ee/10759.html

热点排行