Created
April 7, 2014 07:06
-
-
Save azam/10015873 to your computer and use it in GitHub Desktop.
Sample Spring application context to autowired DynamoDB client, with region or endpoint settings from proeprties or environment variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans | |
xmlns="http://www.springframework.org/schema/beans" | |
xmlns:aop="http://www.springframework.org/schema/aop" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:mvc="http://www.springframework.org/schema/mvc" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation=" | |
http://www.springframework.org/schema/mvc | |
http://www.springframework.org/schema/mvc/spring-mvc.xsd | |
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/aop | |
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"> | |
<!-- DynamoDB service --> | |
<!-- Configure from environment variables --> | |
<bean | |
id="awsCredentials" | |
class="com.amazonaws.auth.BasicAWSCredentials"> | |
<constructor-arg value="${AWS_ACCESS_KEY_ID}" /> | |
<constructor-arg value="${AWS_SECRET_KEY}" /> | |
</bean> | |
<!-- NOTE: It is better to wire the interface (om.amazonaws.services.dynamodbv2.AmazonDynamoDB) inside your code instead of om.amazonaws.services.dynamodbv2.AmazonDynamoDBClient, but leave the bean mapping below to the impl class. --> | |
<bean | |
id="client" | |
class="com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient"> | |
<constructor-arg ref="awsCredentials" /> | |
</bean> | |
<bean | |
id="region_enum" | |
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> | |
<property name="targetClass"> | |
<value>com.amazonaws.regions.Regions</value> | |
</property> | |
<property name="targetMethod"> | |
<value>fromName</value> | |
</property> | |
<property name="arguments"> | |
<list> | |
<value>${AWS_REGION}</value> | |
</list> | |
</property> | |
</bean> | |
<bean | |
id="region" | |
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> | |
<property name="targetClass"> | |
<value>com.amazonaws.regions.Region</value> | |
</property> | |
<property name="targetMethod"> | |
<value>getRegion</value> | |
</property> | |
<property name="arguments"> | |
<list> | |
<ref local="region_enum" /> | |
</list> | |
</property> | |
</bean> | |
<bean | |
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> | |
<property name="targetObject"> | |
<ref local="client" /> | |
</property> | |
<property name="targetMethod"> | |
<value>setRegion</value> | |
</property> | |
<property name="arguments"> | |
<list> | |
<ref local="region" /> | |
</list> | |
</property> | |
</bean> | |
<!-- Use this if setting endpoint url is preferred over region, i.e. when using DynamoDB local | |
<bean | |
class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> | |
<property name="targetObject"> | |
<ref local="client" /> | |
</property> | |
<property name="targetMethod"> | |
<value>setEndpoint</value> | |
</property> | |
<property name="arguments"> | |
<list> | |
<value>${AWS_DYNAMODB_ENDPOINT}</value> | |
</list> | |
</property> | |
</bean> | |
--> | |
</beans> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment