报错信息如下
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.2.RELEASE)
2020-01-11 15:56:15.154 INFO 58552 --- [ main] com.project.demo.DemoApplication : Starting DemoApplication on PC-20180323TDYI with PID 58552 (started by Administrator in D:\intellij workspace\demo)
2020-01-11 15:56:15.160 INFO 58552 --- [ main] com.project.demo.DemoApplication : No active profile set, falling back to default profiles: default
2020-01-11 15:56:16.154 WARN 58552 --- [ main] o.m.s.mapper.ClassPathMapperScanner : No MyBatis mapper was found in '[com.project.demo.mapper]' package. Please check your configuration.
2020-01-11 15:56:16.764 INFO 58552 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2020-01-11 15:56:16.776 INFO 58552 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-01-11 15:56:16.777 INFO 58552 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.29]
2020-01-11 15:56:17.382 INFO 58552 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-01-11 15:56:17.382 INFO 58552 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2067 ms
2020-01-11 15:56:17.573 WARN 58552 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'musController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'musService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.project.demo.ext.mapper.UserBeanExtMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup="", name="", description="", authenticationType=CONTAINER, type=java.lang.Object.class, mappedName="")}
2020-01-11 15:56:17.577 INFO 58552 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2020-01-11 15:56:17.877 INFO 58552 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-01-11 15:56:18.102 ERROR 58552 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
A component required a bean of type 'com.project.demo.ext.mapper.UserBeanExtMapper' that could not be found.
Action:
Consider defining a bean of type 'com.project.demo.ext.mapper.UserBeanExtMapper' in your configuration.
Process finished with exit code 1
因为我在idea里更换了一下bean盒mapper的目录,增加了ext目录存放实际使用的文件,idea帮你把很多目录都改过来了,我自己只修改了application.yml里的这个地方
mybatis:
mapper-locations: classpath:ext/mapper/*.xml #注意:一定要对应mapper映射xml文件的所在路径
type-aliases-package: com.project.demo.ext.entity # 注意:对应实体类的路径
所以遗漏了一处MapperScan注解的修改
@MapperScan(value=“com.project.demo.mapper”)
改为
@MapperScan(value=“com.project.demo.ext.mapper”)
package com.project.demo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@MapperScan(value="com.project.demo.ext.mapper")
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}