无法使用存储库上的保存来持久化spring数据mongodb

lnlaulya  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(267)

我使用spring数据mongodb和嵌入式mongodb来持久化数据。
pom.xml

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>de.flapdoodle.embed</groupId>
        <artifactId>de.flapdoodle.embed.mongo</artifactId>

    </dependency>

应用性能

spring.data.mongodb.port=2019
  spring.data.mongodb.database=testdb
  spring.data.mongodb.host=localhost

主要类别:

@SpringBootApplication 
  @EnableAutoConfiguration
  @EnableMongoRepositories(basePackages = { "com.koka.mongotest.repo"})
  public class MongotestApplication {

    public static void main(String[] args) {
    SpringApplication.run(MongotestApplication.class, args);
   }

}

enity或域类:

@Document
  public class Person 
   {
       @Indexed
       private String personId;
        private String name; 
        //getter and setters
    }

回购:

@Repository
   public interface PersonRepo extends MongoRepository { //No Custom emthod}

服务层:

@Service
   public class ServiceImpl {
         @Autowired
         PresonRepo repo;
        public void saveJon(Person p )
       {
         repo.save(p);
      }
   }

但是int db被保存为

{"_id":{"$oid":"60e18f9d7eb50d70b56b543f"},"_class":"com.koka.mongotest.entity.Person"}

但该person对象保存的信息未被保存。请就此提出建议,

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题