Skip to content

Commit bc290f1

Browse files
authored
Merge pull request eugenp#691 from anataliocs/BAEL-223-Integrate-DynamoDB-into-a-Spring-Boot-Application-using-Spring-Data
BAEL-223 - Integrate DynamoDB into a Spring Boot Application using Sp…
2 parents 4570627 + 5444f7c commit bc290f1

15 files changed

Lines changed: 456 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target/
2+
.settings/
3+
.classpath
4+
.project
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

‎spring-boot-data-dynamodb/pom.xml‎

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.baeldung</groupId>
5+
<artifactId>spring-boot-dynamodb</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<name>Spring Boot Actuator</name>
9+
<description>This is simple boot application for Spring boot actuator test</description>
10+
11+
<parent>
12+
<artifactId>spring-boot-starter-parent</artifactId>
13+
<groupId>org.springframework.boot</groupId>
14+
<version>1.2.3.RELEASE</version>
15+
<relativePath/>
16+
</parent>
17+
18+
<properties>
19+
<!-- The main class to start by executing java -jar -->
20+
<start-class>com.baeldung.Application</start-class>
21+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<java.version>1.8</java.version>
23+
<spring.version>4.3.1.RELEASE</spring.version>
24+
</properties>
25+
26+
<dependencyManagement>
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.data</groupId>
30+
<artifactId>spring-data-releasetrain</artifactId>
31+
<version>Gosling-SR1</version>
32+
<type>pom</type>
33+
<scope>import</scope>
34+
</dependency>
35+
</dependencies>
36+
</dependencyManagement>
37+
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-starter-web</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-actuator</artifactId>
46+
</dependency>
47+
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-starter-security</artifactId>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>io.dropwizard.metrics</groupId>
55+
<artifactId>metrics-core</artifactId>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>com.h2database</groupId>
60+
<artifactId>h2</artifactId>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.springframework.boot</groupId>
65+
<artifactId>spring-boot-starter-test</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter</artifactId>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.jayway.jsonpath</groupId>
75+
<artifactId>json-path</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.springframework.boot</groupId>
80+
<artifactId>spring-boot-starter-mail</artifactId>
81+
</dependency>
82+
83+
<dependency>
84+
<groupId>org.webjars</groupId>
85+
<artifactId>bootstrap</artifactId>
86+
<version>3.3.4</version>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>com.amazonaws</groupId>
91+
<artifactId>aws-java-sdk-dynamodb</artifactId>
92+
<version>1.11.34</version>
93+
</dependency>
94+
<dependency>
95+
<groupId>com.github.derjust</groupId>
96+
<artifactId>spring-data-dynamodb</artifactId>
97+
<version>4.3.1</version>
98+
</dependency>
99+
<dependency>
100+
<groupId>org.apache.httpcomponents</groupId>
101+
<artifactId>httpclient</artifactId>
102+
<version>4.5.2</version>
103+
</dependency>
104+
</dependencies>
105+
106+
<build>
107+
<finalName>spring-boot</finalName>
108+
<resources>
109+
<resource>
110+
<directory>src/main/resources</directory>
111+
<filtering>true</filtering>
112+
</resource>
113+
</resources>
114+
115+
<plugins>
116+
117+
<plugin>
118+
<groupId>org.springframework.boot</groupId>
119+
<artifactId>spring-boot-maven-plugin</artifactId>
120+
</plugin>
121+
122+
<plugin>
123+
<groupId>org.apache.maven.plugins</groupId>
124+
<artifactId>maven-compiler-plugin</artifactId>
125+
<configuration>
126+
<source>1.8</source>
127+
<target>1.8</target>
128+
</configuration>
129+
</plugin>
130+
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-war-plugin</artifactId>
134+
</plugin>
135+
136+
</plugins>
137+
138+
</build>
139+
140+
<repositories>
141+
<repository>
142+
<id>spring-snapshots</id>
143+
<name>Spring Snapshots</name>
144+
<url>https://repo.spring.io/snapshot</url>
145+
<snapshots>
146+
<enabled>true</enabled>
147+
</snapshots>
148+
</repository>
149+
<repository>
150+
<id>spring-milestones</id>
151+
<name>Spring Milestones</name>
152+
<url>https://repo.spring.io/milestone</url>
153+
<snapshots>
154+
<enabled>false</enabled>
155+
</snapshots>
156+
</repository>
157+
</repositories>
158+
<pluginRepositories>
159+
<pluginRepository>
160+
<id>spring-snapshots</id>
161+
<name>Spring Snapshots</name>
162+
<url>https://repo.spring.io/snapshot</url>
163+
<snapshots>
164+
<enabled>true</enabled>
165+
</snapshots>
166+
</pluginRepository>
167+
<pluginRepository>
168+
<id>spring-milestones</id>
169+
<name>Spring Milestones</name>
170+
<url>https://repo.spring.io/milestone</url>
171+
<snapshots>
172+
<enabled>false</enabled>
173+
</snapshots>
174+
</pluginRepository>
175+
</pluginRepositories>
176+
177+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
6+
7+
@SpringBootApplication
8+
@ComponentScan(basePackages = { "com.baeldung" })
9+
public class Application {
10+
public static void main(String[] args) {
11+
SpringApplication.run(Application.class, args);
12+
}
13+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.baeldung.spring.data.es.config;
2+
3+
import com.amazonaws.auth.AWSCredentials;
4+
import com.amazonaws.auth.BasicAWSCredentials;
5+
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
6+
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
7+
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories;
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.context.annotation.Bean;
10+
import org.springframework.context.annotation.Configuration;
11+
import org.springframework.util.StringUtils;
12+
13+
@Configuration
14+
@EnableDynamoDBRepositories(basePackages = "com.baeldung.spring.data.es.repositories")
15+
public class DynamoDBConfig {
16+
17+
@Value("${amazon.dynamodb.endpoint}")
18+
private String amazonDynamoDBEndpoint;
19+
20+
@Value("${amazon.aws.accesskey}")
21+
private String amazonAWSAccessKey;
22+
23+
@Value("${amazon.aws.secretkey}")
24+
private String amazonAWSSecretKey;
25+
26+
@Bean
27+
public AmazonDynamoDB amazonDynamoDB() {
28+
AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient(amazonAWSCredentials());
29+
if (!StringUtils.isEmpty(amazonDynamoDBEndpoint)) {
30+
amazonDynamoDB.setEndpoint(amazonDynamoDBEndpoint);
31+
}
32+
return amazonDynamoDB;
33+
}
34+
35+
@Bean
36+
public AWSCredentials amazonAWSCredentials() {
37+
return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);
38+
}
39+
40+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.baeldung.spring.data.es.model;
2+
3+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
4+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey;
5+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
6+
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
7+
8+
@DynamoDBTable(tableName = "ProductInfo")
9+
public class ProductInfo {
10+
private String id;
11+
private String msrp;
12+
private String cost;
13+
14+
public ProductInfo() {
15+
}
16+
17+
public ProductInfo(String cost, String msrp) {
18+
this.msrp = msrp;
19+
this.cost = cost;
20+
}
21+
22+
@DynamoDBHashKey
23+
@DynamoDBAutoGeneratedKey
24+
public String getId() {
25+
return id;
26+
}
27+
28+
@DynamoDBAttribute
29+
public String getMsrp() {
30+
return msrp;
31+
}
32+
33+
@DynamoDBAttribute
34+
public String getCost() {
35+
return cost;
36+
}
37+
38+
public void setId(String id) {
39+
this.id = id;
40+
}
41+
42+
public void setMsrp(String msrp) {
43+
this.msrp = msrp;
44+
}
45+
46+
public void setCost(String cost) {
47+
this.cost = cost;
48+
}
49+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.baeldung.spring.data.es.repositories;
2+
3+
import com.baeldung.spring.data.es.model.ProductInfo;
4+
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
5+
import org.springframework.data.repository.CrudRepository;
6+
7+
import java.util.List;
8+
9+
@EnableScan
10+
public interface ProductInfoRepository extends CrudRepository<ProductInfo, String> {
11+
List<ProductInfo> findById(String id);
12+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
server.port=8080
2+
server.contextPath=/springbootapp
3+
management.port=8081
4+
management.address=127.0.0.1
5+
6+
endpoints.shutdown.enabled=true
7+
8+
endpoints.jmx.domain=Spring Sample Application
9+
endpoints.jmx.uniqueNames=true
10+
11+
spring.jmx.enabled=true
12+
endpoints.jmx.enabled=true
13+
14+
## for pretty printing of json when endpoints accessed over HTTP
15+
http.mappers.jsonPrettyPrint=true
16+
17+
## Configuring info endpoint
18+
info.app.name=Spring Sample Application
19+
info.app.description=This is my first spring boot application G1
20+
info.app.version=1.0.0
21+
22+
## Spring Security Configurations
23+
security.user.name=admin1
24+
security.user.password=secret1
25+
management.security.role=SUPERUSER
26+
27+
logging.level.org.springframework=INFO
28+
29+
#AWS Keys
30+
amazon.dynamodb.endpoint=http://localhost:8000/
31+
amazon.aws.accesskey=test1
32+
amazon.aws.secretkey=test1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
spring.output.ansi.enabled=never
2+
server.port=7070
3+
4+
# Security
5+
security.user.name=admin
6+
security.user.password=password
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<configuration>
2+
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
14+
</configuration>

0 commit comments

Comments
 (0)