I am restarting by application programmatically. But when i run my application its show below error
No qualifying bean of type 'org.springframework.cloud.context.restart.RestartEndpoint' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}"}}
I also added below properties in my application.properties but still showing the same error.
management.endpoints.web.exposure.include=restart
management.endpoint.restart.enabled=true
Is there anything missing. kindly suggest.
CodePudding user response:
Make sure all of your concerned classes are correctly annotated with @configuration, @Service, @Component, @Controller, or @Repository as required.
This exception clearly tells that it can't able to inject the dependency of specified class due to an unrecognized bean. So make sure you autowired its instance within the referred class.
Hope it helps you!:)
CodePudding user response:
In the spring framework, there are three ways to configure beans as follows,
- Annotation-based configuration - Using @Service or @Component annotations, scope details can be provided with @Scope annotation.
- XML-based annotation - The XML-based configuration can be loaded automatically by writing some boilerplate code in the web.xml file.
- Java-based configuration - We can configure spring beans using java programs. Important annotations used in there are @Configuration, @ComponentScan, and @Bean.
We are getting an example like below, Cohort needs to add the Trainees collaborator. Assume that the Trainee bean is not defined yet.
@Component
public class Cohort {
@Autowired
private Trainee traineeDependency;
}
So after running this code, we get an error which is having the following,
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.traineeexample.model.Trainee] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
So why does this error come, Normally the beans are scanned by classpath scanning and they should be correctly annotated with @Service, @Component, @Controller, or @Repository. Once they are anonotated properly and on running the below component scan with proper path your application ust run withot any issues.
@Configuration
@ComponentScan("com.traineeexample.Trainee")
public class JavaConfig {
}
Read more: click