我已经实现了Spring Data Repository,它使用@RepositoryRestResource注释扩展了MongoRepository以将它们标记为REST端点。但是当映射请求ID时,出现以下异常

java.lang.IllegalArgumentException: Couldn't find PersistentEntity for type class io.sample.crm.models.Merchant!


仓库:

@RepositoryRestResource(collectionResourceRel = "account",path = "account")
public interface MerchantRepository extends MongoRepository<Merchant,String> {

}


GET请求正在尝试:

http://localhost:9090/crm/account/


响应 :

{
"cause": null,
"message": "Couldn't find PersistentEntity for type class io.apptizer.crm.apptizercrmservice.models.Merchant!"
}


另外,我为每个存储库配置了两个数据库。

Application.yml文件:

spring:
  autoconfigure:
    exclude: org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration

mongodb:
   primary:
     host: 127.0.0.1
     port: 27017
     database: db_sample_admin_crm
      rest:
        base-path: /crm
   secondary:
     host: 127.0.0.1
     port: 27017
     database: sample_lead_forms
       rest:
         base-path: /reports


主类:

@SpringBootApplication(scanBasePackages = "io.example")
@Configuration
@ComponentScan({"io.example"})
@EntityScan("io.example")
public class App {

public static void main(String[] args) throws Exception {
    SpringApplication.run(App.class, args);
    InitAuth.initialize();
    InitAuth.generateToken();
  }
}


这里可能出什么问题了?

最佳答案

当我遇到同样的问题时,我将@Id更改为Long类型。

请检查您的extends MongoRepository<Merchant,String>是否与Merchant的ID类型相同。

关于java - 扩展MongoRepository的Repository的REST端点不会被映射,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56143533/

10-09 00:16