【发布时间】:2019-10-02 06:07:06
【问题描述】:
我已经实现了 Spring Data Repositories,它使用 @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();
}
}
这里可能出了什么问题?
【问题讨论】:
-
为什么你的网址里有crm? localhost:9090/crm/account/...can't 是localhost:9090/account??
-
希望这会有所帮助:stackoverflow.com/q/22824840/2987755,
-
@MSD 路径正确,因为
base-path: /crm -
随便猜测一下,
Merchant集合中是否有任何数据,如果没有,请尝试添加一些虚拟对象并检查 -
对不起,我认为基本 URL 未配置。所以我尝试使用 localhost:9090/account 。然后它给了我这个错误'"cause": null, "message": "Couldn't find PersistentEntity for type class io.apptizer.crm.apptizercrmservice.models.Merchant!"'
标签: java spring spring-data-rest mongorepository