0

APPLICATION FAILED TO START


Description:

Field adminService in com.controller.AdminController required a bean of type 'com.service.AdminService' 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.service.AdminService' in your configuration.

Rohan
  • 33
  • 8

3 Answers3

1

Use this snippet of code it will work.

@Controller
public class AdminController{

private AdminService adminService;

@Autowired
public AdminController(AdminService adminService){
  this.adminService=adminService;
}
}

And also use @Service annotation above the AdminService Interface.

0

Update to @ComponentScan(basePackages = {"com.cybage.*"}) in DoctorOnFingerTipsApplication.java class

  • Tried that, As soon I change the `@ComponentScan(basePackages = {"com.cybage.controller"})` to anything,I get this error `ERROR 26064 o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springApplicationAdminRegistrar' defined in class path resource [org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication` – Rohan Jul 13 '21 at 06:19
  • you are calling run method twice in DoctorOnFingerTipsApplication.class checkout this link for more reference .https://stackoverflow.com/questions/48567562/beancreationexception-error-creating-bean-with-name-springapplicationadminregi – sachin kumar Jul 13 '21 at 06:59
0

The line

@ComponentScan(basePackages = {"com.cybage.controller"})

in DoctorOnFingerTipsApplication.java tells to scan components in the package com.cybage.controller directory only.

Since your AdminService is in 'com.cybage.service' package, springboot does not register this as a component.

So change the ComponentScan to scan all packages where you think your components will be present. If you intend to write your components within directories(/services, /respositories, etc. for example) in 'com.cybage' package, update your ComponentScan to :

@ComponentScan(basePackages = {"com.cybage.*"})

where '*' corresponds to all items within the 'com.cybage' package.

Jerin D Joy
  • 750
  • 6
  • 11
  • Tried that, As soon I change the `@ComponentScan(basePackages = {"com.cybage.controller"})` to anything,I get this error `ERROR 26064 o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springApplicationAdminRegistrar' defined in class path resource [org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication` – Rohan Jul 13 '21 at 06:23
  • This is entirely another error with the JMXConfiguration class and has no link to the above mentioned issue. You can check answers for this issue here : https://stackoverflow.com/questions/41317645/springapplicationadminregistrar-invocation-of-init-method-failed-nested-excep – Jerin D Joy Jul 13 '21 at 06:26