spring boot 启动时报错

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.2.RELEASE)

2019-07-24 16:59:47.127  INFO 12304 --- [  restartedMain] com.example.Application                  : Starting Application on coco-PC with PID 12304 (D:\Users\coco\eclipse-workspace\springboot-learning\target\classes started by coco in D:\Users\coco\eclipse-workspace\springboot-learning)
2019-07-24 16:59:47.129  INFO 12304 --- [  restartedMain] com.example.Application                  : No active profile set, falling back to default profiles: default
2019-07-24 16:59:47.164  INFO 12304 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-07-24 16:59:47.164  INFO 12304 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-07-24 16:59:48.186  INFO 12304 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-07-24 16:59:48.203  INFO 12304 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-07-24 16:59:48.203  INFO 12304 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.14]
2019-07-24 16:59:48.209  INFO 12304 --- [  restartedMain] 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:\Program Files\Java\jre1.8.0_181\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_181/bin/server;C:/Program Files/Java/jre1.8.0_181/bin;C:/Program Files/Java/jre1.8.0_181/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;D:\app\coco\product\11.2.0\dbhome_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;D:\Program Files\Microsoft SQL Server\100\Tools\Binn\;D:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;D:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;D:\mysql-5.7.14-winx64\bin;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Windows Kits\8.0\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Common Files\Autodesk Shared\;;D:\Java\jdk1.8.0_121\bin;D:\Programs\Microsoft VS Code Insiders\bin;D:\mysql-5.7.24-winx64\bin;D:\eclipse\jee-2018-12\eclipse;;.]
2019-07-24 16:59:48.294  INFO 12304 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-07-24 16:59:48.295  INFO 12304 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1131 ms
2019-07-24 16:59:48.344  WARN 12304 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cityServiceImpl': Unsatisfied dependency expressed through field 'cityDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.dao.CityDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2019-07-24 16:59:48.346  INFO 12304 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-07-24 16:59:48.360  INFO 12304 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-24 16:59:48.511 ERROR 12304 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 

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

Description:

Field cityDao in com.example.service.impl.CityServiceImpl required a bean of type 'com.example.dao.CityDao' 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.example.dao.CityDao' in your configuration.

感觉像是dao对象没有创建成功。。。求指点

如果你用的是mybatis。 你要添加mapper的扫描路径。

  • 如果你用的是jpa啥的,有没有加@Repository注解
  • 主配置类是否在最外层包下

在启动入口 和接口类中都加入了注解,还是没解决。。是我加的不对吗
入口:@SpringBootApplication

@ComponentScan
接口类
@Mapper

@ComponentScan

少一个。

@MapperScan(basePackages = { "com.xxx.xxx.mapper" })

@ComponentScan 扫描的是Spring的组件。不包含mybatis的。需要使用mybatis提供的注解@MapperScan 来指定mapper接口的路径。

解决了。谢谢!!