1.选springboot版本
<properties> <java.version>8</java.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <spring-boot.version>2.6.13</spring-boot.version> </properties>
2.加依赖
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-spring-boot3-starter</artifactId> <version>3.5.5</version> </dependency>
3.配yml
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8 username: root password: root
4.写mapper
@Mapper public interface UserMapper extends BaseMapper<User> { }
好了,接下来该报错了:找不到mapper里的bean
Description: Field userMapper in com.security.service.UserService required a bean of type 'com.security.mapper.UserMapper' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.security.mapper.UserMapper' in your configuration.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.security.test.MapperTest': Unsatisfied dependency expressed through field
'userMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.security.mapper.UserMapper' available: expected
at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
——————————
原因出在第一第二步:我选的是springboot2,导入pom依赖却来了个springboot3的mp
<dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.5</version> </dependency>
修改pom依赖即可,想不到我在一年之后又遇到了这种弱智问题 :-( 安详的死了
标签:mapper,factory,springframework,bean,不到,security,com From: https://www.cnblogs.com/kun1790051360/p/18310612