XYYHC
December 11, 2019, 7:08am
1
异常信息
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersController'
异常截图
刚刚开始的一个demo小项目,一直报这个错,注解什么的我都加了,弄了很久解决不了这个问题,求助各位,谢谢
SqlSessionFactory
没成功注入。应该是你的mybatis
没配置正确。
发你的配置,不要截图 ,贴代码。
XYYHC
December 11, 2019, 7:14am
3
#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有两个核心的配置。
配置Mapper映射文件的扫描路径,通过 yaml配置,可以有多个
mybatis.mapper-locations[0]=classpath:mapper/**/*-mapper.xml
mybatis.mapper-locations[1]=classpath:mapper/**/*-mapper-ext.xml
配置Mapper接口的扫描路径,在启动类上通过注解配置
@MapperScan(basePackages = { "io.springboot.mapper"})
参考
SpringBoot整合MyBatis
整合的前提是,必须先配置好了数据源
依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>${mybatis-spring-boot-star…
1 Like
XYYHC
December 11, 2019, 8:05am
5
我试了一下,还是不行,并报如下错误:
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 Like
你把换行符删除了,就写在一行,端口也声明出来,试试看吧。我也看不出你这url
配置有啥问题。
XYYHC
December 11, 2019, 8:27am
11
刚刚我就已经把换行符删了,还是有问题。
我把项目打包发给了朋友,他基本没改什么内容,但是可以运行,不报错,我晕了
XYYHC
December 11, 2019, 8:34am
12
我叫他把项目打包发给我,在我电脑上也能跑了,我服了。
谢谢你了,老哥,这个错误我真的晕了,很感谢你的耐心回答,谢谢
2 Likes