![](/img/trans.png)
[英]Class required a bean of type 'java.lang.String' that could not be found
[英]How to resolve required a bean of type 'java.lang.String' that could not be found
我收到以下錯誤:
equired a bean of type 'java.lang.String' that could not be found.
08-Dec-2021 06:49:02 [sshexec]
08-Dec-2021 06:49:02 [sshexec] The injection point has the following annotations:
08-Dec-2021 06:49:02 [sshexec] - @org.springframework.beans.factory.annotation.Autowired(required=true)
08-Dec-2021 06:49:02 [sshexec]
08-Dec-2021 06:49:02 [sshexec]
08-Dec-2021 06:49:02 [sshexec] Action:
08-Dec-2021 06:49:02 [sshexec]
08-Dec-2021 06:49:02 [sshexec] Consider defining a bean of type 'java.lang.String' in your configuration.
以下是我的課程:
@Configuration
public class CloudConfig {
@Autowired
private ReadAwsApplicationProperties readAwsApplicationProperties;
List<AmazonSNS> amazonSNSClientArray = new ArrayList<>();
@Bean
public List<AmazonSNS> amazonSnsClient() {
}
}
有人可以幫我解決問題嗎? 感謝您的時間。
問題在於以下代碼片段:
@Bean
public AWSCredentialsProvider genericProvisioningAWSCredentials(String awsAccessKeyId, String awsSecretKeyId) {
return new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKeyId, awsSecretKeyId));
}
這將指示 Spring 注入兩個您似乎尚未定義為 Spring 管理的 Bean 的String
。
在我看來,您實際上並不需要AWSCredentialsProvider
作為 Spring 管理的 Bean(您只是在上面的方法中使用此方法構建AmazonSNSClientBuilder
),因此只需刪除@Bean
注釋並將該方法設為私有:
@Configuration
public class CloudConfig {
@Autowired
private ReadAwsApplicationProperties readAwsApplicationProperties;
List<AmazonSNS> amazonSNSClientArray = new ArrayList<>();
@Bean
public List<AmazonSNS> amazonSnsClient() {
for (int i = 0; i < readAwsApplicationProperties.getEnv().size(); i++)
{
amazonSNSClientArray.add(AmazonSNSClientBuilder.standard()
.withRegion(readAwsApplicationProperties.getEnv().get(i).getGeneric().getProv().getAws().getRegion())
.withCredentials(genericProvisioningAWSCredentials(readAwsApplicationProperties.getEnv().get(i).getGeneric().getProv().getAws().getAccessKeyId(), readAwsApplicationProperties.getEnv().get(i).getGeneric().getProv().getAws().getAwsSecretKeyId()))
.build());
}
logger.info(" The size of sns client is " + amazonSNSClientArray.size());
return amazonSNSClientArray;
}
private AWSCredentialsProvider genericProvisioningAWSCredentials(String awsAccessKeyId, String awsSecretKeyId) {
return new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKeyId, awsSecretKeyId));
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.