amazon web services - Spring Cloud AWS - AmazonS3 client is always null -


i'm trying implement file upload amazon s3 bucket using spring cloud project.

according documentation:

"a com.amazonaws.services.s3.transfer.transfermanager can created in application code , injected pre-configured com.amazonaws.services.s3.amazons3 client created spring cloud aws resource loader configuration."

this sample code doesnt work though:

public class simpleresourceloadingbean {  @autowired private amazons3 amazons3;  public void withtransfermanager() {     transfermanager transfermanager = new transfermanager(this.amazons3);     transfermanager.upload("mybucket","filename",new file("somefile")); } 

}

the amazons3 variable null.

my spring context config follows:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"  xmlns:context="http://www.springframework.org/schema/context"  xmlns:aws-context="http://www.springframework.org/schema/cloud/aws/context"  xmlns:mvc="http://www.springframework.org/schema/mvc"  xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  http://www.springframework.org/schema/cloud/aws/context http://www.springframework.org/schema/cloud/spring-cloud-aws-context.xsd">  <aws-context:context-credentials>  <aws-context:simple-credentials access-key="key" secret-key="secret" /> </aws-context:context-credentials>  <aws-context:context-region region="eu-central-1"/>  <aws-context:context-resource-loader/>  <bean id="awstransfermanager" class="mytest.cloud.aws.awstransfermanager" /> 

i'm using class testing:

public class awstransfermanager {  @autowired private amazons3 amazons3;  public void upload() throws amazonserviceexception, amazonclientexception, interruptedexception {     transfermanager tx = new transfermanager(amazons3);     system.out.println(amazons3); //always null } 

the test:

@test public void awstest() throws exception {     applicationcontext cxt = new classpathxmlapplicationcontext("meta-inf/spring/spring-context.xml");     awstransfermanager manager = (awstransfermanager)getcontext().getbean("awstransfermanager");     manager.upload(); } 

okay, figured out, missing

<context:annotation-config /> 

part in spring config.


Comments