spring boot 中添加mongodb支持

1、添加maven依赖

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

2、application.properties配置文件中配置mongodb访问参数

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=dbname

3、继承MongoRepository接口,实现对应Repository类

public interface AnalogRepository extends MongoRepository<Analog, String> {
}

4、@SpringBootApplication下面添加Repositories类扫描

@EnableMongoRepositories(basePackageClasses = AnalogRepository.class)

 

posted on 2017-09-15 16:45  一路前行  阅读(847)  评论(0编辑  收藏  举报