Error creating bean with name ‘bookService‘ defined in file ‘...’ Initialization of bean failed
今天在学习Spring事务管理的时候碰到了一个bug,如图:

异常信息说容器没法创建名为“bookService”的bean,我仔细检查了注解和配置文件里的信息,都没有错误。。。看了看大佬们给出的解决方案,就只剩下jar包的版本不一致这个可能了。。
然后我又重新创建了一个项目,我在B站Spring课程的评论区找到了一个老师授课时的代码记录,我替换了原方案中的所有jar包,然后慢慢尝试发现,只要组名为org.springframework的jar包版本一致就能成功了!

如果你的注解和配置文件都没有出错的话,检查一下jar包,组名为org.springframework的jar包版本必须保持一致!
项目所用jar包信息
<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.11</version><scope>test</scope></dependency><!--*********************************************************--><!--组名为org.springframework的jar包版本必须保持一致--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId> org.springframework</groupId><artifactId>spring-aspects</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId> org.springframework</groupId><artifactId>spring-aop</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId> org.springframework</groupId><artifactId>spring-expression</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId> org.springframework</groupId><artifactId>spring-core</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId> org.springframework </groupId><artifactId>spring-jdbc</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId> org.springframework </groupId><artifactId>spring-orm</artifactId><version>5.2.9.RELEASE</version></dependency><dependency><groupId> org.springframework </groupId><artifactId>spring-tx</artifactId><version>5.2.9.RELEASE</version></dependency><!--*********************************************************--><dependency><groupId>net.sourceforge.cglib</groupId><artifactId>com.springsource.net.sf.cglib</artifactId><version>2.2.0</version></dependency><dependency><groupId>org.aopalliance</groupId><artifactId>com.springsource.org.aopalliance</artifactId><version>1.0.0</version></dependency><dependency><groupId> org.aspectj</groupId><artifactId>com.springsource.org.aspectj.weaver</artifactId><version>1.6.8.RELEASE</version></dependency><dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>RELEASE</version><scope>compile</scope></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.22</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.2.6</version></dependency><dependency><groupId> commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.1.3</version></dependency>
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
