Giter Club home page Giter Club logo

spring-rest-api-mongodb's Introduction

Build Status

spring-rest-api-mongodb

Starter application for REST API with spring framework and mongodb. This project is based on the https://github.com/kennycyb/spring-rest-api-starter, with added connectivity to MongoDB.

Refer to https://docs.spring.io/spring-boot/docs/current/reference/html/ for more information.

pom.xml

Use WAR packaging:

<packaging>war</packaging>

Use Spring Framwork

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.RELEASE</version>
</parent>

Dependencies

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.jayway.jsonpath</groupId>
        <artifactId>json-path</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
		<groupId>com.fasterxml.jackson.dataformat</groupId>
		<artifactId>jackson-dataformat-xml</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>		
</dependencies>

Configuration: src/main/resources/application.yml

spring:
  data:
    mongodb:
      host: localhost
      port: 27017
      database: spring-rest-api

Externalize configuration (via Environment)

spring:
  data:
    mongodb:
      host: ${SPRING_MONGO_HOST}
      port: ${SPRING_MONGO_PORT}
      database: spring-rest-api

Using tomcat standalone

Edit /usr/share/tomcat8/bin/setenv.sh, add "SPRING_MONGO_HOST" and "SPRING_MONGO_PORT", example:

export CATALINA_OPTS=" \
...
...
	-DSPRING_MONGO_HOST=localhost \
	-DSPRING_MONGO_PORT=27017
"

Deploy to OpenShift

Deployment Environment Variables

Key Value Description
SPRING_PROFILES openshift Load the application-openshift.yml
SPRING_MONGO_HOST hostname
SPRING_MONGO_PORT port
SPRING_MONGO_USER user
SPRING_MONGO_PASSWORD password
SPRING_MONGO_DATABASE database

spring-rest-api-mongodb's People

Contributors

kennycyb avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.