qq_42717662 2021-07-16 19:10 采纳率: 0%
浏览 93

spring boot bean一直注入失败

报错问题如下:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-07-16 18:54:32.083 ERROR 17740 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'userMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [C:\demo\target\classes\com\example\demo\mapper\UserMapper.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 [C:\demo\target\classes\mapper\DictMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 142; columnNumber: 1; 文件提前结束。
    at 

配置文件:
mybatis:
  configuration:
    map-underscore-to-camel-case: true
  mapper-locations: classpath:mapper/*.xml   #\u914D\u7F6E\u6620\u5C04\u6587\u4EF6
  type-aliases-package: com.example.demo.bean #\u914D\u7F6E\u5B9E\u4F53\u7C7B

spring:
  datasource:
    name: ssm 
    driver-class-name: com.mysql.cj.jdbc.Driver 
    url: jdbc:mysql://127.0.0.1:3306/lol?useUnicode = true&characterEncoding-utf-8&usesSL = true&serverTimezone-UTC #url
    username: root 
    password:   


启动类注解:@MapperScan(basePackages={"com.example.demo.mapper"}),标注了扫描包
结构也没有问题,启动跟bean,dao,service是在同一层。
controller层,service层,mapper层:注解也都写了
xml文件路径我也一一对了都可以跳转,找了一天真的不知道什么原因了

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-07-16 19:34
    关注

    Failed to parse mapping resource: 'file [C:\demo\target\classes\mapper\DictMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 142; columnNumber: 1; 文件提前结束
    这个错误才是主要原因,看看这个xml文件。

    评论

报告相同问题?

问题事件

  • 创建了问题 7月16日

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。