s3Client如何在这个项目中自动连线?

时间:2017-11-08 10:25:17

标签: spring amazon-web-services spring-boot amazon-s3

我正在编写一个Spring应用程序,我想在其中使用AWS S3客户端。我需要做的就是生成签名的URL。使用S3客户端的代码很简单,我已经编写过,但是我试图找出实例化它的正确方法,就像Spring方式一样。

我发现this project on GitHub called spring-boot-aws似乎做了我需要的事情。在FileArchiveService.java,它有these two lines

@Autowired
private AmazonS3Client s3Client;

当我将这些行添加到我的项目中时,我预计会收到此错误:

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'screenshotsController': Unsatisfied dependency expressed through field 's3Client'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.amazonaws.services.s3.AmazonS3Client' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

我搜索了spring-boot-aws试图弄清楚这个bean是如何提供的,我找不到它。我包含相同的依赖项org.springframework.cloud:spring-cloud-aws-context:1.2.1.RELEASE,但这还不够。

关于该项目是如何做的或我应该如何做的任何想法?

我尝试过处理aws-config.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aws-context="http://www.springframework.org/schema/cloud/aws/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                           http://www.springframework.org/schema/cloud/aws/context
                           http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context-1.0.xsd">
    <aws-context:context-credentials>
        <aws-context:simple-credentials access-key="${accessKey:}" secret-key="${secretKey:}"/>
    </aws-context:context-credentials>
    <aws-context:context-resource-loader/>
</beans>

和修改后的AwsResourceConfig.java:〜

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource("classpath:/aws-config.xml")
public class AwsResourceConfig {

}

但我仍然得到同样的错误。

0 个答案:

没有答案