NoSQL databases and microservices are common components of modern applications. One of the most popular NoSQL database is MongoDB and the most wide use framework for microservices is Spring Boot.
This post will guide you through the creation of simple microservice in Spring Boot what use MongoDB Atlas as repository.
Note: MongoDB Atlas is the global cloud database service for modern applications.
Note: CRUD is commonly used shortcut for basic DB operations Create Read Update Delete
Prerequisites
- Created free account on MongoDb Atlas
- Java 13 installed
- Apache Maven installed
- Some IDE (e.g. IntelliJ IDEA)
Creation of Spring Boot app
We have to create Spring Boot application at the beginning.
- Create Spring Boot project by online tool Spring Initializr
- Fill form
- Project: Maven Project
- Language: Java
- Spring Boot: 2.2.1
- Project Metadata / Group: org.korecky
- Project Metadata / Artifact: spring-mongodb-demo
- Project Metadata / Options / Packaging: JAR
- Project Metadata / Options / Java: 13
- Dependencies:
- Spring Data MongoDB
- Click button Generate
Page generated ZIP file with empty project structure. You can open this project in your IDE.
You can compile the project in your IDE or you can do it by maven by running this command in your project directory.
mvn clean install
You have to see “BUILD SUCCESS” message at the end of output. You will see also some errors about MongoSocketOpenException, but don’t worry, we will fix it ASAP.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.186 s
[INFO] Finished at: 2019-11-08T20:34:31+01:00
[INFO] ------------------------------------------------------------------------
Connect to MongoDB Atlas Cloud
We have to little bit prepare MongoDB Atlas Cloud first. We needs user for our application.
- Sign-in to MongoDB Atlas Cloud
- Go to a menu SECURITY / Database Access in the left navigation
- Click on button ADD NEW USER
- Fill new username and password
- Select Read and write to any database option
- Then click Add User
- Done, we have a new user
When we have created user we can connect our application.
- Open your project and paste text below to the configuration file src/main/resources/application.properties in your project
spring.data.mongodb.uri=
spring.data.mongodb.database=test
spring.data.mongodb.uri is an attribute for connection string to MongoDB Atlas
spring.data.mongodb.database is an attribute for database name. If you use free MongoDB Atlas cloud default DB name is test
Let’s find connection string in MongoDB Atlas administration page.
- Sign-in to MongoDB Atlas Cloud (if you are logged out)
- Go to ATLAS / Clusters in the left hand navigation
- Click button Connect
- Select Connect your application in the next screen
- Set form
- DRIVER: Java
- VERSION: 3.6 or later
- Then click Copy button on Connection String Only tab
- We can set spring.data.mongodb.uri in src/main/resources/application.properties file
- Modify username and password by your values
We can compile the project again there is no MongoSocketOpenException error and build is successful.
We will create simple endpoint with CRUD operations in the next part of the series.
блестящий ресурс авиабилеты дешево
ладный вебсайт
vulkan russia casino
правильный веб сайт
скачать 1хбет
oral steroids meaning – testosterone enanthate как принимать, testosterone cypionate injection
Ремонт рулевой рейки Опель – Ремонт рулевой рейки Ситроен Берлинго, Ремонт рулевой рейки Шевроле Авео
Visit Your URL Hydra отзывы
over here https://ruscams-com.ru/videochat-devochki/videochat-ierotichesskii.html
visit site Cannazon Market 2020
Гематомы головного мозга – Мрт или кт головного мозга: что лучше?, Головокружения. Почему голова кружится
go to this site fortnite skin changer chapter 2
олимп бет промокод – бетмастер промокод, винлайн промокод
Айфон цена – Айфон 8, Айфон 12
he said
binary options jobs
неотразимый вебсайт https://plays-fortuna.ru
click now
casino x
read more https://ssn.is
browse around this site Pegatinas de niquel
Visit Website https://ssn.is
Get More Info https://ssn.is
read the full info here pegatinas metalicas adhesivas
Source https://porno150.com/category/%d0%b2-%d0%bc%d0%b0%d1%88%d0%b8%d0%bd%d0%b5/
best 4-cmc – best hexen, Magasin 4-cmc
фулл тилт скачать – фулл тилт покер, ggpokerok бонус