When I change the code in step 8 as follows
in LoginController:
From
LoginService service = new LoginService();
to
@Autowired
LoginService service;
and then add @Component in LoginService.java (inluding import), when I save the changes, the result is this message
2022-01-27 11:50:47.811 INFO 17832 --- [ restartedMain] c.i.s.w.s.SpringBootFirstWebApplication : Starting SpringBootFirstWebApplication using Java 17.0.2 on LT-99999 with PID 17832 (D:\Training\spring-boot-first-web-application\target\classes started by XXXXXX in D:\Training\spring-boot-first-web-application)
2022-01-27 11:50:47.811 INFO 17832 --- [ restartedMain] c.i.s.w.s.SpringBootFirstWebApplication : No active profile set, falling back to default profiles: default
2022-01-27 11:50:47.989 INFO 17832 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-01-27 11:50:47.990 INFO 17832 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-01-27 11:50:47.990 INFO 17832 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-01-27 11:50:48.040 INFO 17832 --- [ restartedMain] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2022-01-27 11:50:48.041 INFO 17832 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-01-27 11:50:48.041 INFO 17832 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 228 ms
2022-01-27 11:50:48.052 WARN 17832 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.in28minutes.springboot.web.service.LoginService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2022-01-27 11:50:48.052 INFO 17832 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-01-27 11:50:48.058 INFO 17832 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-01-27 11:50:48.075 ERROR 17832 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Field service in com.in28minutes.springboot.web.springbootfirstwebapplication.LoginController required a bean of type 'com.in28minutes.springboot.web.service.LoginService' that could not be found.
The injection point has the following annotations:
When I change the code in step 8 as follows in LoginController: From LoginService service = new LoginService(); to @Autowired LoginService service;
and then add @Component in LoginService.java (inluding import), when I save the changes, the result is this message
2022-01-27 11:50:47.811 INFO 17832 --- [ restartedMain] c.i.s.w.s.SpringBootFirstWebApplication : Starting SpringBootFirstWebApplication using Java 17.0.2 on LT-99999 with PID 17832 (D:\Training\spring-boot-first-web-application\target\classes started by XXXXXX in D:\Training\spring-boot-first-web-application) 2022-01-27 11:50:47.811 INFO 17832 --- [ restartedMain] c.i.s.w.s.SpringBootFirstWebApplication : No active profile set, falling back to default profiles: default 2022-01-27 11:50:47.989 INFO 17832 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2022-01-27 11:50:47.990 INFO 17832 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2022-01-27 11:50:47.990 INFO 17832 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56] 2022-01-27 11:50:48.040 INFO 17832 --- [ restartedMain] org.apache.jasper.servlet.TldScanner : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 2022-01-27 11:50:48.041 INFO 17832 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2022-01-27 11:50:48.041 INFO 17832 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 228 ms 2022-01-27 11:50:48.052 WARN 17832 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.in28minutes.springboot.web.service.LoginService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2022-01-27 11:50:48.052 INFO 17832 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2022-01-27 11:50:48.058 INFO 17832 --- [ restartedMain] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2022-01-27 11:50:48.075 ERROR 17832 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Field service in com.in28minutes.springboot.web.springbootfirstwebapplication.LoginController required a bean of type 'com.in28minutes.springboot.web.service.LoginService' that could not be found.
The injection point has the following annotations:
Action:
Consider defining a bean of type 'com.in28minutes.springboot.web.service.LoginService' in your configuration.
I have tried changing my JRE and entries in pom.xml, but am unable to fix.
I'm running Eclipse Version 2021-12 (4.22.0)