Java_chaozi
Java_chaozi
采纳率28.6%
2017-12-24 06:42 阅读 5.1k
已采纳

spring-boot 与mybtis项目整合报错,感觉是DataSource没注入成功

5

2017-12-24 14:17:17,501:WARN main (AbstractApplicationContext.java:551) - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericDao' defined in file [E:\spring_boot\shpping-admin\yichao-admin\target\classes\com\yichao\yichaoadmin\commons\dao\impl\GenericDaoImpl.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: @Resource annotation requires a single-arg method: public org.apache.ibatis.session.SqlSession com.yichao.yichaoadmin.commons.dao.impl.GenericDaoImpl.getSqlSession()
2017-12-24 14:17:17,501:INFO main (DirectJDKLog.java:179) - Stopping service [Tomcat]
2017-12-24 14:17:17,523:INFO main (AutoConfigurationReportLoggingInitializer.java:101) -

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-12-24 14:17:17,523:ERROR main (SpringApplication.java:771) - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genericDao' defined in file [E:\spring_boot\shpping-admin\yichao-admin\target\classes\com\yichao\yichaoadmin\commons\dao\impl\GenericDaoImpl.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: @Resource annotation requires a single-arg method: public org.apache.ibatis.session.SqlSession com.yichao.yichaoadmin.commons.dao.impl.GenericDaoImpl.getSqlSession()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:526) ~[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.yichao.yichaoadmin.YichaoAdminApplication.main(YichaoAdminApplication.java:10) [classes/:?]
Caused by: java.lang.IllegalStateException: @Resource annotation requires a single-arg method: public org.apache.ibatis.session.SqlSession com.yichao.yichaoadmin.commons.dao.impl.GenericDaoImpl.getSqlSession()
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$2.doWith(CommonAnnotationBeanPostProcessor.java:421) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:492) ~[spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.buildResourceMetadata(CommonAnnotationBeanPostProcessor.java:387) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.findResourceMetadata(CommonAnnotationBeanPostProcessor.java:340) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(CommonAnnotationBeanPostProcessor.java:297) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:992) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
... 15 more

Process finished with exit code 1

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • 已采纳
    Java_chaozi Java_chaozi 2018-09-29 02:16

    需要在spring boot 扫描 加上@MapperScan(basePackages= "com.yulece.app.management.user.provide.repositories") 进行手动扫描

    点赞 评论 复制链接分享
  • yyl_xs_vip yyl_xs_vip 2017-12-24 06:52

    应该是数据源不对。你可以先检查数据源

    点赞 评论 复制链接分享
  • qazwsx_65321 qazwsx_65321 2017-12-24 07:26

    检查两个项目是否有冲突的内容

    点赞 评论 复制链接分享
  • it_zhangwei 路漫漫兮其修远兮 2017-12-24 07:31

    你的注入方式有问题吧@Resource annotation requires a single-arg method: public org.apache.ibatis.session.SqlSession必须要有唯一个生成sqlSession的公共方法。

    点赞 评论 复制链接分享
  • gongjiaoka 一个半吊子的码农 2017-12-24 10:56

    检查springboot的所需的jar包是否完整

    点赞 评论 复制链接分享
  • qq_34031663 China小嘿 2017-12-24 12:20

    看一下 genericDao 这个类的路径是否能被spring 扫描到,或者spring是否正常加载的

    点赞 评论 复制链接分享
  • zql112003 轩妈食品IT部 2017-12-24 14:25

    检查下你扫描包的路径和你的 配置类的包

    点赞 评论 复制链接分享
  • qq_38623459 被忘记的默客 2017-12-28 08:51

    generatorConfig.xml网上有很多例子,看看你的各种路径对吗,如果你用maven引包应该没啥

    点赞 评论 复制链接分享

相关推荐