Spring Boot and how to configure connection details to MongoDB?

后端 未结 6 2042
死守一世寂寞
死守一世寂寞 2020-12-12 18:45

Being new to Spring Boot I am wondering on how I can configure connection details for MongoDB. I have tried the normal examples but none covers the connection details.

6条回答
  •  春和景丽
    2020-12-12 19:22

    In a maven project create a file src/main/resources/application.yml with the following content:

    spring.profiles: integration
    # use local or embedded mongodb at localhost:27017
    ---
    spring.profiles: production
    spring.data.mongodb.uri: mongodb://:@:/
    

    Spring Boot will automatically use this file to configure your application. Then you can start your spring boot application either with the integration profile (and use your local MongoDB)

    java -jar -Dspring.profiles.active=integration your-app.jar
    

    or with the production profile (and use your production MongoDB)

    java -jar -Dspring.profiles.active=production your-app.jar
    

提交回复
热议问题