关于SpringBoot的sqlSessionFactory错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.2019-12-06 14:42:49.734 ERROR 14644 --- [ main] o.s.boot.SpringApplication ...
摘要由CSDN通过智能技术生成
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-12-06 14:42:49.734 ERROR 14644 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app': Unsatisfied dependency expressed through field 'userDOMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDOMapper' defined in file [D:\IDEA_workspace\Mmiaosha\target\classes\com\miaoshaproject\dao\UserDOMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\IDEA_workspace\Mmiaosha\target\classes\mapping\ItemStockDOMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.miaoshaproject.dao.ItemStockDOMapper.BaseResultMap
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当在Spring Boot应用程序中使用MyBatis时,可能会遇到"property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"的错误。这个错误的原因是配置文件中没有正确地定义`sqlSessionFactory`或`sqlSessionTemplate`。 解决这个问题的方法是: 1. 确保在配置文件中正确地定义了`sqlSessionFactory`或`sqlSessionTemplate`。可以通过在application.properties或application.yml文件中设置属性来完成这个任务。例如,在application.properties文件中,可以使用以下代码定义`sqlSessionFactory`: ```properties mybatis.spring.sqlSessionFactoryBeanName=sqlSessionFactory ``` 或者,在application.yml文件中,可以使用以下代码定义`sqlSessionTemplate`: ```yaml mybatis.spring.sqlSessionTemplateBeanName=sqlSessionTemplate ``` 2. 确保在配置类中正确地配置了MyBatis。可以使用`@MapperScan`注解扫描包含Mapper接口的路径。例如: ```java @Configuration @MapperScan("com.example.mapper") public class MyBatisConfig { // other configurations... } ``` 或者,如果使用XML文件进行配置,确保在配置文件中包含了正确的XML映射器路径。例如: ```xml <mybatis:scan base-package="com.example.mapper" /> ``` 3. 同样重要的是,检查依赖项是否正确添加到项目的pom.xml文件中。确保添加了MyBatis和MyBatis-Spring的正确版本。 通过正确定义`sqlSessionFactory`或`sqlSessionTemplate`,正确配置MyBatis,以及检查依赖项,应该能够解决"property 'sqlSessionFactory' or 'sqlSessionTemplate' are required"的错误

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值