DZone
Database Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Database Zone > Spring Data, MongoDB, and Spring Boot

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.

Tim Spann user avatar by
Tim Spann
CORE ·
Jan. 15, 16 · Database Zone · Tutorial
Like (11)
Save
Tweet
24.02K Views

Join the DZone community and get the full member experience.

Join For Free

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);
    }
}
Spring Framework Spring Boot MongoDB Data (computing)

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 7 Best MQTT Client Tools Worth Trying
  • MuleSoft Logs Integration With Datadog
  • Discussing Backend for Front-end
  • On Some Aspects of Big Data Processing in Apache Spark, Part 1: Serialization

Comments

Database Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo