Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ganchix/morphia-spring-boot-starter
Spring boot starter for use Morphia in a Spring way easily.
https://github.com/ganchix/morphia-spring-boot-starter
java-8 mongodb morphia spring spring-boot spring-boot-starter
Last synced: 10 days ago
JSON representation
Spring boot starter for use Morphia in a Spring way easily.
- Host: GitHub
- URL: https://github.com/ganchix/morphia-spring-boot-starter
- Owner: ganchix
- License: mit
- Created: 2017-05-05T12:52:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-20T12:33:18.000Z (over 4 years ago)
- Last Synced: 2023-07-29T10:09:17.489Z (over 1 year ago)
- Topics: java-8, mongodb, morphia, spring, spring-boot, spring-boot-starter
- Language: Java
- Size: 110 KB
- Stars: 14
- Watchers: 5
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Spring boot starter Morphia [![Build Status](https://travis-ci.org/ganchix/morphia-spring-boot-starter.svg?branch=master)](https://travis-ci.org/ganchix/morphia-spring-boot-starter) [![codecov](https://codecov.io/gh/ganchix/morphia-spring-boot-starter/branch/master/graph/badge.svg)](https://codecov.io/gh/ganchix/morphia-spring-boot-starter) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.ganchix/morphia-spring-boot-parent/badge.svg?style=plastic)](https://maven-badges.herokuapp.com/maven-central/io.github.ganchix/morphia-spring-boot-parent) [![GitHub stars](https://img.shields.io/github/stars/badges/shields.svg?style=social&label=Star)](https://github.com/ganchix/morphia-spring-boot-starter)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fganchix%2Fmorphia-spring-boot-starter.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fganchix%2Fmorphia-spring-boot-starter?ref=badge_shield)Spring boot starter for use [Morphia](https://mongodb.github.io/morphia/) in a Spring way easily.
# Table of Contents
- [Overview](#overview)
- [Getting started](#getting-started)
- [License](#license)### Overview
This implementation offers a Spring way to use [Morphia](https://mongodb.github.io/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 exampleFirst 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:
```java
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:
```java
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 removeQuery = datastore.createQuery(Account.class)
.filter("user", user);
datastore.delete(removeQuery);
}
}
```#### Integration using `@SpringBootApplication` or `@EnableAutoConfiguration`
Only add Maven dependency:
```xml
io.github.ganchix
morphia-spring-boot-starter
1.0.1```
#### Without `@SpringBootApplication` or `@EnableAutoConfiguration`
You need a `@ComponentScan` in the root package.
Add Maven dependency:
```xml
io.github.ganchix
morphia-spring-boot
1.0.1```
Import auto configuration `MorphiaAutoConfiguration`:
```java
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](LICENSE.md) for details.
Copyright (c) 2017 Rafael Ríos Moya
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fganchix%2Fmorphia-spring-boot-starter.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fganchix%2Fmorphia-spring-boot-starter?ref=badge_large)