Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Data, MongoDB, and Spring Boot

DZone's Guide to

Spring Data, MongoDB, and Spring Boot

You really can quickly develop a microservice to access MongoDB from Java 8 with little coding. Give it a try... easy like Sunday morning.

· Database Zone
Free Resource

Read why times series is the fastest growing database category.

Image title

It’s so simple, I almost don’t believe it.  And, if this seems to hard, try using JHipster.

You really can quickly develop a microservice to access MongoDB from Java 8 with little coding.   Give it a try.  Java 8 + Spring Boot + Gradle + MongoDB + YAML.  Easy like Sunday morning.

Gradle

 compile(“org.springframework.boot:spring-boot-starter-data-mongodb”)

Application.yml

spring.profiles.default: local

Application-local.yml

spring.data.mongodb.database: my-db-engine
spring.data.mongodb.uri: mongodb://localhost:2701

Repository

import org.springframework.data.repository.CrudRepository;
import com.mysite.service.stuff.model.MongoModel;

public interface IMongoModelEnabledRepository extends CrudRepository<MongoModel, String>
{
    public MongoModel findByDomain(String domain);
}

Usage

@Autowired

IMongoModelEnabledRepository myrepo;

myrepo.findByDomain(domain);

Spring Boot Application

@PropertySource(“classpath:application.yml”)
@EnableAsync
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Learn how to get 20x more performance than Elastic by moving to a Time Series database.

Topics:
spring architecture ,spring data ,nosql ,mongodb ,gradle ,spring boot ,yaml

Published at DZone with permission of Tim Spann, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}