【发布时间】:2015-09-09 12:57:41
【问题描述】:
我在 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)
这是我的 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"));
我刚开始在亚马逊网络服务上工作,所以请帮助我。
【问题讨论】:
-
顺便说一句:EnableAutoConfiguration、ComponentScan 和 Configuration 注释都是多余的,因为 SpringBootApplication 暗示
标签: java maven amazon-web-services spring-boot