Skip to content

Commit b02d83d

Browse files
committed
BAEL-223 - Integrate DynamoDB into a Spring Boot Application using Spring Data
1 parent fa05954 commit b02d83d

15 files changed

Lines changed: 480 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
###The Course
2+
The "REST With Spring" Classes: http://bit.ly/restwithspring

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

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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</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>org.baeldung.boot.DemoApplication</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+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-web</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-data-jpa</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-actuator</artifactId>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-security</artifactId>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>io.dropwizard.metrics</groupId>
53+
<artifactId>metrics-core</artifactId>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>com.h2database</groupId>
58+
<artifactId>h2</artifactId>
59+
</dependency>
60+
61+
<dependency>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-starter-test</artifactId>
64+
<scope>test</scope>
65+
</dependency>
66+
67+
<dependency>
68+
<groupId>org.springframework.boot</groupId>
69+
<artifactId>spring-boot-starter</artifactId>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.jayway.jsonpath</groupId>
73+
<artifactId>json-path</artifactId>
74+
<scope>test</scope>
75+
</dependency>
76+
<dependency>
77+
<groupId>org.springframework.boot</groupId>
78+
<artifactId>spring-boot-starter-mail</artifactId>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.subethamail</groupId>
82+
<artifactId>subethasmtp</artifactId>
83+
<version>3.1.7</version>
84+
<scope>test</scope>
85+
</dependency>
86+
87+
<dependency>
88+
<groupId>org.webjars</groupId>
89+
<artifactId>bootstrap</artifactId>
90+
<version>3.3.4</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>org.webjars</groupId>
94+
<artifactId>jquery</artifactId>
95+
<version>2.1.4</version>
96+
</dependency>
97+
<dependency>
98+
<groupId>org.springframework.data</groupId>
99+
<artifactId>spring-data-jpa</artifactId>
100+
<version>1.10.2.RELEASE</version>
101+
</dependency>
102+
<dependency>
103+
<groupId>com.amazonaws</groupId>
104+
<artifactId>aws-java-sdk-dynamodb</artifactId>
105+
<version>1.11.34</version>
106+
</dependency>
107+
<dependency>
108+
<groupId>org.socialsignin</groupId>
109+
<artifactId>spring-data-dynamodb</artifactId>
110+
<version>4.2.1</version>
111+
</dependency>
112+
</dependencies>
113+
114+
<build>
115+
<finalName>spring-boot</finalName>
116+
<resources>
117+
<resource>
118+
<directory>src/main/resources</directory>
119+
<filtering>true</filtering>
120+
</resource>
121+
</resources>
122+
123+
<plugins>
124+
125+
<plugin>
126+
<groupId>org.springframework.boot</groupId>
127+
<artifactId>spring-boot-maven-plugin</artifactId>
128+
</plugin>
129+
130+
<plugin>
131+
<groupId>org.apache.maven.plugins</groupId>
132+
<artifactId>maven-compiler-plugin</artifactId>
133+
<configuration>
134+
<source>1.8</source>
135+
<target>1.8</target>
136+
</configuration>
137+
</plugin>
138+
139+
<plugin>
140+
<groupId>org.apache.maven.plugins</groupId>
141+
<artifactId>maven-war-plugin</artifactId>
142+
</plugin>
143+
144+
</plugins>
145+
146+
</build>
147+
148+
<repositories>
149+
<repository>
150+
<id>spring-snapshots</id>
151+
<name>Spring Snapshots</name>
152+
<url>https://repo.spring.io/snapshot</url>
153+
<snapshots>
154+
<enabled>true</enabled>
155+
</snapshots>
156+
</repository>
157+
<repository>
158+
<id>spring-milestones</id>
159+
<name>Spring Milestones</name>
160+
<url>https://repo.spring.io/milestone</url>
161+
<snapshots>
162+
<enabled>false</enabled>
163+
</snapshots>
164+
</repository>
165+
<repository>
166+
<id>opensourceagility-release</id>
167+
<url>http://repo.opensourceagility.com/release/</url>
168+
</repository>
169+
</repositories>
170+
<pluginRepositories>
171+
<pluginRepository>
172+
<id>spring-snapshots</id>
173+
<name>Spring Snapshots</name>
174+
<url>https://repo.spring.io/snapshot</url>
175+
<snapshots>
176+
<enabled>true</enabled>
177+
</snapshots>
178+
</pluginRepository>
179+
<pluginRepository>
180+
<id>spring-milestones</id>
181+
<name>Spring Milestones</name>
182+
<url>https://repo.spring.io/milestone</url>
183+
<snapshots>
184+
<enabled>false</enabled>
185+
</snapshots>
186+
</pluginRepository>
187+
</pluginRepositories>
188+
189+
</project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.spring.data.es.config;
2+
3+
import org.apache.commons.lang3.StringUtils;
4+
import org.springframework.beans.factory.annotation.Value;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.ComponentScan;
7+
import org.springframework.context.annotation.Configuration;
8+
9+
import com.amazonaws.auth.AWSCredentials;
10+
import com.amazonaws.auth.BasicAWSCredentials;
11+
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
12+
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
13+
14+
@Configuration
15+
@ComponentScan(basePackages = { "com.baeldung.spring.data.es.service" })
16+
public class DynamoDBConfig {
17+
18+
@Value("${amazon.dynamodb.endpoint}")
19+
private String amazonDynamoDBEndpoint;
20+
21+
@Value("${amazon.aws.accesskey}")
22+
private String amazonAWSAccessKey;
23+
24+
@Value("${amazon.aws.secretkey}")
25+
private String amazonAWSSecretKey;
26+
27+
@Bean
28+
public AmazonDynamoDB amazonDynamoDB() {
29+
AmazonDynamoDB amazonDynamoDB = new AmazonDynamoDBClient(amazonAWSCredentials());
30+
if (StringUtils.isNotEmpty(amazonDynamoDBEndpoint)) {
31+
amazonDynamoDB.setEndpoint(amazonDynamoDBEndpoint);
32+
}
33+
return amazonDynamoDB;
34+
}
35+
36+
@Bean
37+
public AWSCredentials amazonAWSCredentials() {
38+
return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);
39+
}
40+
41+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
7+
public class ProductInfo {
8+
private String id;
9+
private String msrp;
10+
private String cost;
11+
12+
public ProductInfo() {
13+
}
14+
15+
public ProductInfo(String cost, String msrp) {
16+
this.msrp = msrp;
17+
this.cost = cost;
18+
}
19+
20+
@DynamoDBHashKey
21+
@DynamoDBAutoGeneratedKey
22+
public String getId() {
23+
return id;
24+
}
25+
26+
@DynamoDBAttribute
27+
public String getMsrp() {
28+
return msrp;
29+
}
30+
31+
@DynamoDBAttribute
32+
public String getCost() {
33+
return cost;
34+
}
35+
36+
public void setId(String id) {
37+
this.id = id;
38+
}
39+
40+
public void setMsrp(String msrp) {
41+
this.msrp = msrp;
42+
}
43+
44+
public void setCost(String cost) {
45+
this.cost = cost;
46+
}
47+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.spring.data.es.repository;
2+
3+
import java.util.List;
4+
5+
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
6+
import org.springframework.data.repository.CrudRepository;
7+
8+
import com.baeldung.spring.data.es.model.ProductInfo;
9+
10+
@EnableScan
11+
public interface ProductInfoRepository extends CrudRepository<ProductInfo, String> {
12+
13+
List<ProductInfo> findById(String id);
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.baeldung;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.context.ApplicationContext;
5+
6+
@org.springframework.boot.autoconfigure.SpringBootApplication
7+
public class Application {
8+
private static ApplicationContext applicationContext;
9+
10+
public static void main(String[] args) {
11+
applicationContext = SpringApplication.run(Application.class, args);
12+
}
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
##jolokia.config.debug=true
12+
##endpoints.jolokia.enabled=true
13+
##endpoints.jolokia.path=jolokia
14+
15+
spring.jmx.enabled=true
16+
endpoints.jmx.enabled=true
17+
18+
## for pretty printing of json when endpoints accessed over HTTP
19+
http.mappers.jsonPrettyPrint=true
20+
21+
## Configuring info endpoint
22+
info.app.name=Spring Sample Application
23+
info.app.description=This is my first spring boot application G1
24+
info.app.version=1.0.0
25+
26+
## Spring Security Configurations
27+
security.user.name=admin1
28+
security.user.password=secret1
29+
management.security.role=SUPERUSER
30+
31+
logging.level.org.springframework=INFO
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)