@Mapper和@Repository的问题

 

 

今天用最新的

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>

<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.7.1</version>
</dependency>

提示找不到Mapper曾的bean,Mapper中使用@Repository

解决方案:
方案1启动类中添加 @MapperScan("xxx.xxx.xxx.mapper")
方案2
@Repository换成@Mapper

:: Spring Boot :: (v2.1.2.RELEASE)

2019-01-24 16:17:53.735 INFO 13800 --- [ main] c.d.v.VwtaterMybatisplusApplication : Starting VwtaterMybatisplusApplication on LAPTOP-F72VHEUV with PID 13800 (C:\workspace\test\vwtater-mybatisplus\target\classes started by vwater in C:\workspace\test\vwtater-mybatisplus)
2019-01-24 16:17:53.742 INFO 13800 --- [ main] c.d.v.VwtaterMybatisplusApplication : No active profile set, falling back to default profiles: default
2019-01-24 16:17:54.783 WARN 13800 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.djtu.vwtater]' package. Please check your configuration.
2019-01-24 16:17:55.640 INFO 13800 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-01-24 16:17:55.665 INFO 13800 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-01-24 16:17:55.665 INFO 13800 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-01-24 16:17:55.672 INFO 13800 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\software\java\jdk\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\Docker\Docker\Resources\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Python27\;C:\Python27\Scripts;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\software\java\jdk\bin;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\software\Git\cmd;C:\software\apache-maven-3.5.4\bin\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\software\tortoiseSVN\bin;C:\software\python;C:\WINDOWS\System32\OpenSSH\;C:\Users\vwater\Downloads\apache-jmeter-5.0\\bin;C:\Program Files\Amazon\AWSCLI\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\software\python\Scripts\;C:\software\python\;C:\Users\vwater\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;;.]
2019-01-24 16:17:55.818 INFO 13800 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-01-24 16:17:55.818 INFO 13800 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1992 ms
2019-01-24 16:17:55.910 WARN 13800 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeController': Unsatisfied dependency expressed through field 'employeeMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.djtu.vwtater.mapper.EmployeeMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2019-01-24 16:17:55.915 INFO 13800 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2019-01-24 16:17:55.949 INFO 13800 --- [ main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-24 16:17:56.068 ERROR 13800 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :

***************************
APPLICATION FAILED TO START
***************************

Description:

Field employeeMapper in com.djtu.vwtater.controller.EmployeeController required a bean of type 'com.djtu.vwtater.mapper.EmployeeMapper' 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.djtu.vwtater.mapper.EmployeeMapper' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:52242', transport: 'socket'

Process finished with exit code 1

 

posted @ 2019-01-24 16:29  vwater  阅读(12099)  评论(0编辑  收藏  举报