Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property

本文记录了一次由于阿里云Maven中央仓库更新Mybatis包,导致SpringBoot项目因未指定版本而报错的经历。问题表现为项目启动时依赖注入失败,原因是Mybatis版本被更新为不兼容的版本。解决方法是将pom.xml中Mybatis的版本指定为特定版本,如2.1.1,从而避免使用RELEASE最新版本。作者建议在项目中尽量使用明确的版本号以防止类似问题发生。
摘要由CSDN通过智能技术生成

来来来,记录一下阿里云Maven中央仓库的坑,当然最主要还是自身pom.xml设置问题。

昨天项目启动还好好的,为什么今天项目一启动就报错了呢?(线上项目服务器没重启的话也是正常可以访问的,只要一重启线上服务器就会发现线上服务器Maven在编译的时候下载了很多新的jar包,当然,线上服务器maven的settings.xml配置文件和本地机子配置的同样使用的是阿里云的maven仓库)

项目是使用的是springboot框架

本地开发环境Maven远程仓库的settings.xml配置文件使用了国内的阿里云中央仓库地址(为了提高下载引入的Jar包速度,懂的都懂)

	<mirrors>
		<!-- mirror | Specifies a repository mirror site to use instead of a igven
			repository. The repository that | this mirror serves has an ID that matches
			the mirrorOf element of this mirror. IDs are used | for inheritance and direct
			lookup purposes, and must be unique across the set of mirrors. | <mirror>
			<id>mirrorId</id> <mirrorOf>repositoryId</mirrorOf> <name>Human Readable
			Name for this Mirror.</name> <url>http://my.repository.com/repo/path</url>
			</mirror> -->
		<!-- 阿里云仓库 -->
		<mirror>
			<id>alimaven</id>
			<mirrorOf>central</mirrorOf>
			<name>aliyun maven</name>
			<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
		</mirror>

		<mirror>
			<id>alimaven</id>
			<name>aliyun maven</name>
			<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
			<mirrorOf>central</mirrorOf>
		</mirror>
	</mirrors>

刚好今天人家阿里云Maven中央仓库更新了Mybatis最新的jar包,自己项目中的mybatis包也没有写指定版本,所以就导致阿里云Maven远程仓库更新了Mybatis的引入包,而自己项目的pom也导入了阿里云远程仓库的最新Mybatis包导致项目不兼容而导致启动报错

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2022-11-27 17:03:19,287:ERROR main (SpringApplication.java:771) - Application startup failed
 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'activitiesExhibitionController': Unsatisfied dependency expressed through field 'servletUtil'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servletUtil': Unsatisfied dependency expressed through field 'userActiveMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userActiveMapper' defined in file [/Users/mac/IdeaProjects/yiwei/shinemi-realiart/target/classes/com/shinemi/realiart/mapper/UserActiveMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
	at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]
	at com.shinemi.realiart.Application.main(Application.java:20) [classes/:?]

一步步排查原因:本地连接服务器mysql数据库   正常、springboot扫描Mapper.xml映射文件  正常、但是报错就是提示我需要sql工厂session属性,我就纳闷了,昨天啥都没动,项目启动还好好的,今天怎么就见鬼了呢

解决方法:

去找到项目中pom.xml的mybatis引入jar

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>RELEASE</version>
        </dependency>

看到项目中的mybatis的版本号设置了吗?  <version>RELEASE</version>

mybatis引入的jar包没有设置指定版本号,而是使用RELEASE最新发布的版本,所以当阿里云远程中央仓库发布了RELEASE的mybatis Jar包后,本地启动项目经过Maven编译启动后,自动下载阿里云远程的最新Mybatis的发布版本Jar引入导致项目不兼容

所以我这里要修改Mybatis使用指定版本号的jar包

使用了2.1.1版本的试试

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>

设置好指定版本号后,Maven重新导入Jar包,启动项目成功!!!

以后还是尽量设置指定的版本号吧,别用RELEASE最新发布版本的Jar了。

我真的哭死,搞了一天排查原因.....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值