Coder Social home page Coder Social logo

rahul-ghadge / spring-boot-mongodb-crud Goto Github PK

View Code? Open in Web Editor NEW
47.0 1.0 50.0 47 KB

Spring boot MongoDB CRUD (Create, Read, Update, Delete) example using MongoTemplate and MongoRepository

Java 100.00%
spring-boot mongorepository mongotemplate spring-data spring-boot-mongodb-crud

spring-boot-mongodb-crud's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

spring-boot-mongodb-crud's Issues

latest verison of mongoDB provided by docker, should use auth uri to connect

As title, the lastest version of mongo, not allow seperate setting under application properties and cause authentication errors.

ref.

If you use the Mongo 3.0 Java driver, spring.data.mongodb.host and spring.data.mongodb.port are not supported. In such cases, spring.data.mongodb.uri should be used to provide all of the configuration.

The following uri setting works.

spring.data.mongodb.uri=mongodb://admin:123456@localhost:27017/spring_boot_mongo_app?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false

Before starts the app, should run the following commands to create db admin with user name as admin and password as 123456.

docker exec -it mongo mongo admin
db.createUser({ user:'admin',pwd:'123456',roles:[ { role:'userAdminAnyDatabase', db: 'admin'},"readWriteAnyDatabase"]}

code

Issue Title: Replace CORSFilter with WebMvcConfigurer for CORS configuration

We currently have a CORS filter (CORSFilter) in our codebase to handle Cross-Origin Resource Sharing. However, there is a more modern and Spring-centric approach using WebMvcConfigurer. This issue aims to replace the existing CORSFilter with the WebMvcConfigurer-based configuration.

PROPOSED CHANGES
Replace the existing CORSFILTER.java class under config with the following configurtaion in DatabaseConfiguration.java

@Bean
public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("*")
                    .allowedHeaders("*")
                    .allowCredentials(false).maxAge(3600);
        }
    };
}

This approach is more in line with modern Spring practices and provides a concise and effective way to handle CORS globally in our Spring Boot application and thereby reduces the boilerplate code

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.