wolfgump

导航

ssh整合,导入structs包后报错 getAnnotation(AnnotatedElement ae,Class<T> annotatetype)找不到

  今天在整合ssh(spring-framework-3.2.5.RELEASE-dist+struts-2.3.15.3-all+hibernate-release-4.2.6.Final)环境的时候,集成了hibernate和spring,经过单元测试,没有问题,集成成功。但是在导入structs包后,项目报错,具体错误如下:

  Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [bean.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [bean.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.getAnnotation(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;

 

   找不到 getAnnotation(AnnotatedElement ae,Class<T> annotatetype)这样的方法,于是我查找了项目中使用spring版本的文档,发现下面这个方法:

 

public static <T extends Annotation> T getAnnotation(AnnotatedElement ae,
                                     Class<T> annotationType)
  Get a single Annotation of annotationType from the supplied Method, Constructor or Field. Meta-annotations will be searched if the annotation is not declared locally on the supplied element.
Parameters:
ae - the Method, Constructor or Field from which to get the annotation
annotationType - the annotation class to look for, both locally and as a meta-annotation
Returns:
the matching annotation or null if not found
Since:
3.1

  文档中显示,3.1以后版本才有这个方法,这是就猜想项目中是不是有3.1一下版本的spring核心包,经过查找,在struts-2.3.15.3这个版本中包含了spring-core-3.0.5.RELEASE.jar这样一个jar包,低于3.1版本。

  在项目中删除spring-core-3.0.5.RELEASE.jar这个jar,问题就解决了

  另外:使用struts-2.3.15.3 需要注意,此版本中包含了包含里除了spring-core-3.0.5.RELEASE.jar以外的spring需要3.0.5版本的jar包,在使用的时候都需要删除

posted on 2013-12-07 20:14  wolfgump  阅读(685)  评论(0编辑  收藏  举报