错误日志:
Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Z
引入的依赖包:
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>4.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mqtt</artifactId>
<version>4.2.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.eclipse.paho</groupId>
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>de.odysseus.staxon</groupId>
<artifactId>staxon</artifactId>
<version>1.2</version>
</dependency>
根据其他码友的说法,遇到
Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class
这个错误,很大概率是因为jar包冲突导致的。然后我就去排查jar包的版本。
maven库中的spring依赖包版本:
要引入的spring-integration-core包中的spring依赖包版本:
发现Maven库中的Spring-core、spring-aop等jar包的版本是4.3.7-RELEASE,与要引入的spring-integration-core包中的spring依赖包版本4.2.6-RELEASE不一致。
要解决问题,就要使spring-integration-core包中的依赖包版本与maven库中的spring依赖包版本一致。
而在引包的过程中,我们发现spring-integration-core包中的依赖包的版本是spring-integration-core包版本4.2.7-RELEASE的上一版本,即4.2.6-RELEASE。
所以,我们只需要将spring-integration-core的版本号修改为4.3.8-RELEASE。那其中的依赖包版本即为4.3.7-RELEASE,也就与maven库中的spring依赖包版本一致。
再排除掉spring-integration-core包中的spring依赖包
而后,我们又发现,要引入的第二个包spring-integration-mqtt包中已经引入了第一个包spring-integration-core,
所以我们只需要引入spring-integration-mqtt包,再排除掉其中的spring依赖包即可。
更新Maven库,重启项目,成功!