Spring读取静态文件

时间:2018-05-18 10:31:20

标签: spring file amazon-web-services resources

我正在尝试与Amazon CloudFront集成的Spring Web服务。要创建signed url,CloudFront API需要一个包含私钥的java.io.File对象。该文件采用.pem格式,API如下所示:

String signedUrl = CloudFrontUrlSigner.getSignedURLWithCannedPolicy(
                Protocol.https, 
                distributionDomainName, 
                cloudFrontPrivateKeyFile, // KEY FILE
                "/images/img.jpg", 
                cloudFrontKeyPairId, 
                expirationDate);

如何在Spring中将文件加载到内存中?我找到的所有示例都是从资源加载文件,如下所示:

final Resource fileResource = 
                resourceLoader.getResource("classpath:config/pk-mykey.pem");
cloudFrontPrivateKeyFile = fileResource.getFile()

但是,此代码抛出异常:

class path resource [config/pk-mykey.pem] cannot be resolved to absolute file path because it does not reside in the file system:

0 个答案:

没有答案