SpringBoot启动异常

异常信息

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersController'

异常截图




刚刚开始的一个demo小项目,一直报这个错,注解什么的我都加了,弄了很久解决不了这个问题,求助各位,谢谢

SqlSessionFactory 没成功注入。应该是你的mybatis没配置正确。
发你的配置,不要截图 ,贴代码。

#Mysql数据库相关配置

spring.datasource.url=jdbc:mysql://XXXXXX/yhc_wxapp?useUnicode=\
                        true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true
spring.datasource.username=root
spring.datasource.password=XXXXX
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

mybatis.mapper-locations=classpath:mapper/*.xml

MyBatis有两个核心的配置。

  1. 配置Mapper映射文件的扫描路径,通过 yaml配置,可以有多个
mybatis.mapper-locations[0]=classpath:mapper/**/*-mapper.xml
mybatis.mapper-locations[1]=classpath:mapper/**/*-mapper-ext.xml
  1. 配置Mapper接口的扫描路径,在启动类上通过注解配置
@MapperScan(basePackages = { "io.springboot.mapper"})

参考

1 个赞

我试了一下,还是不行,并报如下错误:
Description:

Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

Consider the following:
If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

你这配置文件在哪个位置?名称叫啥?怕是程序没读取到吧?

1 个赞

image

你的这个properties配置文件在哪里?

image
刚刚没截到图,sorry

你把换行符删除了,就写在一行,端口也声明出来,试试看吧。我也看不出你这url配置有啥问题。

刚刚我就已经把换行符删了,还是有问题。

我把项目打包发给了朋友,他基本没改什么内容,但是可以运行,不报错,我晕了

我叫他把项目打包发给我,在我电脑上也能跑了,我服了。
谢谢你了,老哥,这个错误我真的晕了,很感谢你的耐心回答,谢谢

2 个赞