@Configuration
@EnableConfigurationProperties(AWSProperties.class)
@PropertySource("kaizen-batch-common-aws.properties")
public class ResourceConfigAWS {
@Autowired
private AWSProperties awsProperties;
@Autowired
private ResourceLoader resourceLoader;
private static final Logger logger = LoggerFactory.getLogger(ResourceConfigAWS.class);
@Bean
public AmazonS3 amazonS3Client() {
logger.debug("AWS Config: " + this.awsProperties);
BasicAWSCredentials awsCreds = new BasicAWSCredentials("access_key_id", "secret_key_id");
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.withRegion(awsProperties.getRegion())
.build();
return s3Client;
}
@Bean
public SimpleStorageResourceLoader resourceLoader() {
return new SimpleStorageResourceLoader(this.amazonS3Client());
}
@Bean
@StepScope
public Resource getResourceToProcess(@Value("#{jobParameters[T(com.kaizen.batch.common.JobRunnerTemplate).INPUT_FILE_PARAM_NAME]}") String inputFile) {
return this.resourceLoader.getResource(this.awsProperties.getInputLocation() + inputFile);
}
@PostConstruct
public void postConstruct() {
System.out.print("Properties values: " + this.awsProperties);
}
@Bean
public AbstractFileValidator inputFileValidator() {
InputS3Validator inputS3Validator = new InputS3Validator();
inputS3Validator.setRequiredKeys(new String[]{InputFileSystemValidator.INPUT_FILE});
return inputS3Validator;
}
@Bean
public InputFileFinalizerDelegate inputFileFinalizerDelegate() {
InputFileFinalizerDelegate inputFileFinalizerDelegate = new AWSInputFileFinalizerDelegate();
return inputFileFinalizerDelegate;
}
@Bean
public InputFileInitializerDelegate inputFileInitializerDelegate() {
InputFileInitializerDelegate inputFileInitializerDelegate = new AWSInputFileInitializerDelegate();
return inputFileInitializerDelegate;
}
}
@ConfigurationProperties("aws")
@Data
public class AWSProperties {
private static final String SEPARATOR = "/";
private static final String S3_PREFFIX = "s3://";
@Value("${s3.bucket.batch}")
private String bucket;
@Value("${s3.bucket.batch.batch-job-folder}")
private String rootFolder;
@Value("${s3.bucket.batch.input}")
private String inputFolder;
@Value("${s3.bucket.batch.processed}")
private String processedFolder;
@Value("${region}")
private String region;
public String getInputLocation() {
return this.getBasePath() + this.inputFolder + SEPARATOR;
}
public String getProcessedLocation() {
return this.getBasePath() + this.processedFolder + SEPARATOR;
}
private String getBasePath() {
return S3_PREFFIX + this.bucket + SEPARATOR + this.rootFolder + SEPARATOR;
}
}
aws.s3.bucket.batch=com-kaizen-batch-dev
aws.s3.bucket.batch.input=input
aws.s3.bucket.batch.processed=processed
aws.s3.bucket.batch.batch-job-folder=merchant-file
aws.region=us-east-2
注意:我对Configuration类做了一点修改,现在我得到了以下异常:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.kaizen.batch.common.ResourceConfigAWS': Unsatisfied dependency expressed through field 'awsProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'aws-com.kaizen.batch.common.AWSProperties': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 's3.bucket.batch' in value "${s3.bucket.batch}"
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
@configurationproperties
用于将属性文件键与POJO类绑定。您必须执行以下更改才能使代码正常工作。
kaizen-batch-common-aws.
aws.s3.bucket.batch.bucket=com-kaizen-batch-dev
aws.s3.bucket.batch.root-folder=processed
aws.s3.bucket.batch.input-folder=input
aws.s3.bucket.batch.processed-folder=processed
aws.s3.bucket.batch.batch-job-folder=merchant-file
@Component
@ConfigurationProperties(prefix = "aws.s3.bucket.batch")
public class AWSProperties {
private String bucket;
private String rootFolder;
private String inputFolder;
private String processedFolder;
private String region;
// setter require
}
请访问这里的doc
问题内容: 我需要从Docker容器中在后台运行的Java应用程序中启动Selenium。启动失败,因为在运行时无法访问X11环境。请参阅下面的内容。 我该怎么办? 问题 我从安装Java 8和Jetty 9.3.x 的简单程序开始运行一个简单的服务(实际上是selenium的东西)。该服务实际上是为了启动一些需要UI才能执行的事情而设置的。我遇到的问题是其中的任何内容执行失败,因为UI在我运行的
我有一个使用SpringCloud配置的SpringBoot应用程序,但我想在SpringBootApps引导程序中加密SpringCloud配置密码。yml文件。有办法做到这一点吗?下面是一个例子。 Spring Boot应用程序bootstrap.yml
这里有很多关于向ActionBar添加图标的问题,但都没有解决我的问题。如果你知道这个问题的副本,请随意评论或关闭这个问题。 我将我的项目迁移到IntelliJ,我以前的IDE(Eclipse)没有遇到这个问题。 问题:应用程序图标未显示在操作栏中。 我认为默认情况下应该添加它,这就是为什么我不能通过它的XML添加它 这是它的XML 谢谢
问题内容: 我用C语言编写“ hello world”程序 程序编译时显示警告为 这怎么可能?OS如何在不包含任何标题的情况下链接库? 问题答案: 编译器使用对称为的函数的引用来构建源文件, 而无需 知道其实际使用的参数或其返回类型是什么。生成的程序集在程序的静态数据区域中包含字符串地址的,后跟到。 将您的目标文件链接到可执行文件时,链接器会看到对它的引用并提供C标准库函数。通过 巧合 ,你传递的
请帮我学习在地图间导航。我有一张地图散列表 我想生成另一张 == 的地图 这是我的标准。如果0位置的绝对值大于1。-- 这是运行输出 请看留言。谢谢你们!https://i.stack.imgur.com/iaK7j.jpg