morphia-spring-boot

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
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

morphia-spring-boot
Spring boot starter using for morphia integration.
Source Code Management

Source Code Management

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

Download morphia-spring-boot

How to add to project

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

Dependencies

compile (4)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.5
org.springframework.boot : spring-boot-autoconfigure jar 1.5.3.RELEASE
org.mongodb.morphia : morphia jar 1.2.1
org.reflections : reflections jar 0.9.11

test (6)

Group / Artifact Type Version
nl.jqno.equalsverifier : equalsverifier jar 2.2.1
commons-logging : commons-logging jar 1.2
de.flapdoodle.embed : de.flapdoodle.embed.mongo jar 2.0.0
org.powermock : powermock-api-mockito jar 1.6.6
org.powermock : powermock-module-junit4 jar 1.6.6
org.springframework.boot : spring-boot-starter-test jar 1.5.3.RELEASE

Project Modules

There are no modules declared in this project.

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