【问题标题】:Spring + google cloud: No qualifying bean of type 'com.google.cloud.storage.Storage' availableSpring + google cloud:没有可用的“com.google.cloud.storage.Storage”类型的合格bean
【发布时间】:2020-05-24 16:00:01
【问题描述】:

我正在尝试将 spring 库用于谷歌云 API:

spring-cloud-gcp-starter-vision

但是 Spring Application Context 加载失败并报错:

原因:org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源 [org/springframework/cloud/gcp/autoconfigure/vision/CloudVisionAutoConfiguration$VisionOcrConfiguration.class] 中定义名称为“documentOcrTemplate”的 bean 创建错误:不满意通过方法 'documentOcrTemplate' 参数 1 表达的依赖关系;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有“com.google.cloud.storage.Storage”类型的合格 bean 可用:预计至少有 1 个有资格作为自动装配候选者的 bean。依赖注释:{}...

我不知道如何处理它,因为它都是谷歌的代码,在我自己的代码中没有。

仅供参考,这是我尝试使用此库的方式:

@Service
public class OCRServiceImpl implements OCRService {

    private static Log LOGGER = LogFactory.getLog(OCRServiceImpl.class);

    @Autowired
    private CloudVisionTemplate cloudVisionTemplate;

    @Autowired
    private ResourceLoader resourceLoader;

【问题讨论】:

  • 奇怪的是,它在本地工作,一旦放在 GCP 中的容器上抛出 UnsatisfiedDependencyException,我检查了 CloudVisionTemplate 的构造函数,它有 ImageAnnotatorClient。扫描这个包裹怎么样?

标签: spring-boot google-cloud-platform google-cloud-storage spring-cloud-gcp


【解决方案1】:

您需要将 both spring-cloud-gcp-starter-vision 和 spring-cloud-gcp-starter-storage 添加到您的依赖项中。

cloud-vision-ocr-dependencies

【讨论】:

    【解决方案2】:

    你设置 spring.cloud.gcp.vision 了吗?

    @ConfigurationProperties("spring.cloud.gcp.vision")
    

    看看@CloudVisionAutoConfiguration

        @Bean
        @ConditionalOnMissingBean
        public CloudVisionTemplate cloudVisionTemplate(ImageAnnotatorClient imageAnnotatorClient) {
            return new CloudVisionTemplate(imageAnnotatorClient);
        }
    

    看起来你缺少属性配置!!!

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2018-04-20
      • 1970-01-01
      • 2020-01-31
      • 1970-01-01
      • 2016-06-16
      • 1970-01-01
      • 2020-07-27
      • 2018-11-08
      相关资源
      最近更新 更多