目的,实现springboot和MongoDB的整合,后期实现多数据源mysql+MongoDB 实现业务和日志的不同存储
1.pom文件
<!-- mongodb依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
2.bean代码
import lombok.Data;
import javax.persistence.Id;
@Data
public class User {
@Id
private Long id;
private String username;
private Integer age;
public User(Long id, String username, Integer age) {
this.id = id;
this.username = username;
this.age = age;
}
// 省略getter和setter
}
3.