我正在以编程方式重新启动应用程序。但是,当我运行我的应用程序时,它的显示错误如下
没有'org.springframework.cloud.context.restart.RestartEndpoint‘类型的合格bean可用:预期至少有一个bean,这可以作为自动测试的候选。依赖性注释:{}"}}
我还在application.properties中添加了以下属性,但仍然显示了相同的错误。
management.endpoints.web.exposure.include=restart
management.endpoint.restart.enabled=true
有什么遗漏了吗。请给我建议。
更新:
步骤1: POST /env change spring.application.name ok。
步骤2:使用新的/refresh spring.application.name确定ok。
步骤3: /restart =>应用程序停止使用上面的消息(使用来自ConfigServer的新配置运行预期的应用程序)
我将EurekaClient和ConfigClient与bootstrap.yml结合使用。这两种解决方案都失败了: Eureka first和Config first。
发布于 2022-07-13 23:21:59
确保所有相关类都按照需要使用@configuration、@Service、@Component、@Controller或@Repository对其进行了正确注释。
此异常清楚地表明,由于未识别的bean,它无法注入指定类的依赖项。因此,请确保在所引用的类中自动处理它的实例。
希望它对你有帮助!)
发布于 2022-07-14 02:31:01
在spring框架中,有三种配置bean的方法,如下所示:
下面是一个例子,Cohort需要添加学员协作者。假设还没有定义培训人员bean。
@Component
public class Cohort {
@Autowired
private Trainee traineeDependency;
}
所以在运行这段代码之后,我们得到了一个错误,它有以下内容,
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)}
那么为什么会出现这个错误呢?通常情况下,bean是通过类路径扫描来扫描的,并且应该用@Service、@Component、@Controller或@Repository正确地注释它们。一旦它们被正确地连接,并且在运行下面的组件时,用正确的路径扫描,您的应用程序就不会出现任何问题。
@Configuration
@ComponentScan("com.traineeexample.Trainee")
public class JavaConfig {
}
阅读更多:点击
https://stackoverflow.com/questions/72969907
复制相似问题