1. 程式人生 > >關於spring boot無法自動注入bean問題解決方案

關於spring boot無法自動注入bean問題解決方案

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

2017-09-11 16:16:10.367  INFO 14512 --- [           main] com.spring.web.DemoApplication           : Starting DemoApplication on PC2014101864 with PID 14512 (E:\workspacedubbo\boot\boot-web\target\classes started by Administrator in E:\workspacedubbo\boot\boot-web)
2017-09-11 16:16:10.369  INFO 14512 --- [           main] com.spring.web.DemoApplication           : No active profile set, falling back to default profiles: default
2017-09-11 16:16:10.421  INFO 14512 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot
[email protected]
31206beb: startup date [Mon Sep 11 16:16:10 CST 2017]; root of context hierarchy 2017-09-11 16:16:11.710 INFO 14512 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http) 2017-09-11 16:16:11.721 INFO 14512 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2017-09-11 16:16:11.722 INFO 14512 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.16 2017-09-11 16:16:11.856 INFO 14512 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2017-09-11 16:16:11.856 INFO 14512 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1438 ms 2017-09-11 16:16:11.992 INFO 14512 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2017-09-11 16:16:11.995 INFO 14512 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2017-09-11 16:16:11.995 INFO 14512 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2017-09-11 16:16:11.995 INFO 14512 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2017-09-11 16:16:11.995 INFO 14512 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2017-09-11 16:16:12.025 WARN 14512 --- [ main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'demoApplication': Unsatisfied dependency expressed through field 'demoService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.spring.service.DemoService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2017-09-11 16:16:12.026 INFO 14512 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2017-09-11 16:16:12.038 INFO 14512 --- [ main] utoConfigurationReportLoggingInitializer : Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2017-09-11 16:16:12.107 ERROR 14512 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field demoService in com.spring.web.DemoApplication required a bean of type 'com.spring.service.DemoService' that could not be found. Action: Consider defining a bean of type 'com.spring.service.DemoService' in your configuration.

解決辦法: