morphia-spring-boot-parent

Spring boot starter using for morphia integration.

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

io.github.ganchix
ArtifactId

ArtifactId

morphia-spring-boot-parent
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

pom
Description

Description

morphia-spring-boot-parent
Spring boot starter using for morphia integration.
Project URL

Project URL

https://github.com/ganchix/morphia-spring-boot-starter
Source Code Management

Source Code Management

https://github.com/ganchix/morphia-spring-boot-starter/tree/master

Download morphia-spring-boot-parent

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.ganchix/morphia-spring-boot-parent/ -->
<dependency>
    <groupId>io.github.ganchix</groupId>
    <artifactId>morphia-spring-boot-parent</artifactId>
    <version>1.0.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/io.github.ganchix/morphia-spring-boot-parent/
implementation 'io.github.ganchix:morphia-spring-boot-parent:1.0.1'
// https://jarcasting.com/artifacts/io.github.ganchix/morphia-spring-boot-parent/
implementation ("io.github.ganchix:morphia-spring-boot-parent:1.0.1")
'io.github.ganchix:morphia-spring-boot-parent:pom:1.0.1'
<dependency org="io.github.ganchix" name="morphia-spring-boot-parent" rev="1.0.1">
  <artifact name="morphia-spring-boot-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='io.github.ganchix', module='morphia-spring-boot-parent', version='1.0.1')
)
libraryDependencies += "io.github.ganchix" % "morphia-spring-boot-parent" % "1.0.1"
[io.github.ganchix/morphia-spring-boot-parent "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.reflections : reflections jar 0.9.11

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 1.5.3.RELEASE

Project Modules

  • morphia-spring-boot
  • morphia-spring-boot-starter

Spring boot starter Morphia Build Status codecov Maven Central GitHub stars

FOSSA Status

Spring boot starter for use Morphia in a Spring way easily.

Table of Contents

Overview

This implementation offers a Spring way to use Morphia framework, we use the configuration of Spring Data Mongo to instantiate Morphia and Datastore objects, both objects can be injected.

The starter scan Entity annotations to add in datastore and ensure indexes.

Getting started

Code example

First of all need to configure your properties like Spring Data Mongo, a example of application.properties :

spring.data.mongodb.uri=mongodb://user:password@ip:port/database
spring.data.mongodb.repositories.enabled=true

Create your domain classes, for example:

import lombok.Data;
import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;

@Data
@Entity
public class Account {
    
    @Id
    private ObjectId id;
    private String user;
    private Double amount;
    private Long createdDate;
    
}

Create your repositories:

import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
    
@Component
public class AccountRepositoryImpl implements AccountRepository {
    
    @Autowired
    private Datastore datastore;
    
    @Override
    public void delete(String user) {
        Query<Account> removeQuery = datastore.createQuery(Account.class)
                    .filter("user", user);
        datastore.delete(removeQuery);
    }
}

Integration using @SpringBootApplication or @EnableAutoConfiguration

Only add Maven dependency:

<dependency>
    <groupId>io.github.ganchix</groupId>
    <artifactId>morphia-spring-boot-starter</artifactId>
    <version>1.0.1</version>
</dependency>

Without @SpringBootApplication or @EnableAutoConfiguration

You need a @ComponentScan in the root package.

Add Maven dependency:

<dependency>
    <groupId>io.github.ganchix</groupId>
    <artifactId>morphia-spring-boot</artifactId>
    <version>1.0.1</version>
</dependency>

Import auto configuration MorphiaAutoConfiguration:

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
    
@Configuration
@Import(MorphiaAutoConfiguration.class)
public class MorphiaConfig {
    
}

License

Spring boot starter Morphia is licensed under the MIT License. See LICENSE for details.

Copyright (c) 2017 Rafael Ríos Moya

FOSSA Status

Versions

Version
1.0.1
1.0.0