How to configure MongoTemplate on Spring?

Daniel Lopez

I will work with some old projects developed with Spring, I usually work with spring boot so I started doing some tests to practice before starting, I looked for some configuration examples but i just found few examples (there are many info for spring boot but not for spring) and non of them worked for me. Could anyone show me the easiest way to use mongoTemplate with spring?

Suvam Banerjee

spring-boot class :

@SpringBootApplication @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) public class MyApp {...}

Mongo repo :

@Repository public interface UserRepository extends MongoRepository<User, Long> {}

dependency

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>{mongo.driver.version}</version>
</dependency>

also refer to https://mkyong.com/mongodb/spring-data-mongodb-hello-world-example/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related