1.Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
分析:数据库配置出问题,pom中引入了mybatis,引入mybatis后就会加载需要的数据源,找对应的数据源配置就要初始化数据库连接池,这里没找到所以报错
解决:加上数据源配置,建一个file文件,application.yaml
server:
port: 8081
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: root
url: jdbc:mysql://localhost:3306/security?useUnicode=true&characterEncoding=UTF-8
2.Field userMapper in com.dev.security.service.impl.UserServiceImpl required a bean of type ‘com.dev.security.mapper.UserMapper’ that could not be found.
解决:在SecurityApplication中定义,@MapperScan(basePackages = “com.dev.*.mapper”)不可以写成MapperScan(basePackages = “com.dev”),因为包的范围太大,会扫描到service中
3.SqlSession[org.apache.ibatis.session.defaults.DefaultSqlSession@529d3cc5] was not registered for synchronization because synchronization is not active
分析:事务同步器没有激活
解决:在需要事务管理的地方加@Transactional 注解。@Transactional 注解可以被应用于接口定义和接口方法、类定义和类的 public 方法上。