caused by: java.lang.illegalargumentexception: property 'sqlsessionfactory' or 'sqlsessiontemplate' are required
时间: 2023-03-02 19:27:17 浏览: 112
这个错误提示是Java语言中常见的异常信息。它的意思是,出现了一个非法参数异常,原因是缺少必要的属性"sqlsessionfactory"或者"sqlsessiontemplate"。
在Java开发中,这种异常通常是由于程序中缺少了必要的配置或者参数设置而引起的。如果你遇到了这个异常,需要检查程序中是否正确地配置了相应的属性,或者是否正确地传递了必要的参数。
相关问题
Caused by: java.lang.IllegalArgumentException: Property sqlSessionFactory or sqlSessionTemplate are required
这个错误"Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"是因为在SpringBoot整合MyBatis时,未配置sqlSessionFactory或sqlSessionTemplate导致的。为了解决这个问题,你可以按照以下步骤进行操作:
1. 确保你的项目中已经正确引入了MyBatis和MyBatis-Spring的依赖。
2. 在SpringBoot的配置文件(application.properties或application.yml)中添加以下配置:
如果是使用sqlSessionFactory:
```yaml
mybatis:
config-location: classpath:mybatis-config.xml
mapper-locations: classpath:mapper/*.xml
```
如果是使用sqlSessionTemplate:
```yaml
mybatis:
mapper-locations: classpath:mapper/*.xml
```
3. 如果你使用了mybatis-config.xml文件进行MyBatis的配置,确保该文件存在于classpath中,并且配置了正确的数据源和其他相关信息。
完成以上步骤后,重新启动你的应用程序,该错误应该会被解决。
SpringBoot 起项目 Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
根据提供的引用内容,当使用SpringBoot起项目时,可能会出现"Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"异常。这个异常通常是由于Mybatis-Spring版本过高引起的。
解决这个异常的方法是降低Mybatis-Spring的版本。可以通过在pom.xml文件中指定Mybatis-Spring的版本来解决这个问题。例如,将Mybatis-Spring的版本降低到1.3.2:
```xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
```
这样就可以解决"Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"异常了。