无法从aws.properties加载凭据

时间:2015-09-09 12:57:41

标签: java maven amazon-web-services spring-boot

我在java中使用aws ses并收到此错误。我在谷歌搜索但得到我的问题的任何答案。多数民众赞成我在这里提出我的问题。我已多次尝试并完成了我从谷歌获得的所有更改,但没有任何帮助我。这是我的例外..

Exception in thread "main" java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.artle.Application.createAwsCredentials(Application.java:48)
at com.artle.Application.createSimpleEmailService(Application.java:65)
at com.artle.Application.sendTestEmail(Application.java:70)
at com.artle.Application.main(Application.java:78)

Hre是我的 Application.java 文件

@EnableAutoConfiguration
@ComponentScan
@Configuration
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

@Bean
public FilterRegistrationBean SimpleCORSFilter() {
    final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(new SimpleCORSFilter());
    //registrationBean.addUrlPatterns("/api/*");
    return registrationBean;
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
} 

private AWSCredentials createAwsCredentials() throws IOException{

    Properties properties=new Properties();
    properties.load(getClass().getClassLoader().getResourceAsStream(
            "aws.properties"));
AWSCredentials credentials =new BasicAWSCredentials(
        properties.getProperty("aws.accessKey"),
        properties.getProperty("aws.secretKey"));   

AWSCredentials credentials2=new PropertiesCredentials(
        getClass().getClassLoader().getResourceAsStream(
                "aws.properties"));



    return credentials;
}

private AmazonSimpleEmailService createSimpleEmailService() throws IOException{

    return new AmazonSimpleEmailServiceClient(createAwsCredentials());

}

private void sendTestEmail() throws IOException{
 PostMan postMan= new AwsPostMan(createSimpleEmailService());   
 postMan.withFrom("ansh@artle.in").withTo("amit0133@gmail.com").
 withSubject("Email from aws!!").
 withBody("This is a test email from AWS").send();
}

public static void main(String[] args) throws IOException { 

new Application().sendTestEmail();

SpringApplication.run(Application.class, args); 

}

}

行号48是

properties.load(getClass().getClassLoader().getResourceAsStream(
            "aws.properties"));

我刚刚开始研究亚马逊网络服务,所以请帮助我。

1 个答案:

答案 0 :(得分:0)

不确定您的属性文件到底发生了什么。在IDE中运行它与在执行此类操作时实际部署它之间有时会有一些区别。

但我认为您可能想要做的是使用Spring Boot application.properties文件,然后使用@Value注释将其注入Spring

但也许你真正想要做的就是看Spring Cloud AWS为你设置那些东西?