标签:mongodb
pom<!-- <dependency> --> <!-- <groupId>org.mongodb</groupId> --> <!-- <artifactId>mongodb-driver</artifactId> --> <!-- <version>3.6.0</version> --> <!-- </dependency> --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> </dependency>
tried to access method org.bson.types.ObjectId.<init>(III)V from class com.mongodb.Bytes
spring-data-mongodb会自动导入一个mongodb-driver包,该包与项目引入的包版本不一致导致的问题
启动
mongod.exe --config C:\wnn\software\mongodb\data\mongodb.config
视图
robo3t.exe
实现
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; public class CmsMongoRepository<T> { @Autowired protected MongoTemplate mongoTemplate; public void save(T t) { System.out.println("save : " + t.getClass().getName()); mongoTemplate.save(t); } }
import java.util.List; import org.springframework.data.mongodb.repository.MongoRepository; public interface IComponentRepository extends MongoRepository<Component, Long> { List<Component> findByName(String name); Component findById(String id); Component findBySrcEntryPK(String srcEntryPK); }
标签:mongodb
原文地址:http://blog.51cto.com/xinzhilian/2052830