Spring做事务案例出现错误

问题遇到的现象和发生背景

在我自学spring中有个bug出现,我在做一个简单事务案例的时候我做测试没有添加事务时spring和mybatis一切正常运行在加上事务的注解后就完全报错,这里是啥问题

问题相关代码,请勿粘贴截图

报错内容
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springConfig': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: 'org.springframework.core.annotation.AnnotationAttributes org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String)'
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springConfig': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: 'org.springframework.core.annotation.AnnotationAttributes org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String)'

运行结果及报错内容

img

img

img

img

img

img

img

img

明显就是这个bean 不能拿到,在main方法你能取要service对象吗??

关于该问题,我找了一篇非常好的博客,你可以看看是否有帮助,链接:spring编程式事务实现

@EnableTransactionManagement放到启动类上,@Transiaction标注到实现类上

字面上解释就是添加完事物后需要用到 org.springframework.core.annotation.AnnotatedElementUtils.getAnnotationAttributes(java.lang.reflect.AnnotatedElement, java.lang.String),但是这个方法在你的spring里面找不到,所以原因就是:spring-beans和spring-contxt两个的版本不一致,改成一致就行