rahul-ghadge / spring-boot-mongodb-crud Goto Github PK
View Code? Open in Web Editor NEWSpring boot MongoDB CRUD (Create, Read, Update, Delete) example using MongoTemplate and MongoRepository
Spring boot MongoDB CRUD (Create, Read, Update, Delete) example using MongoTemplate and MongoRepository
As title, the lastest version of mongo, not allow seperate setting under application properties and cause authentication errors.
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"]}
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.