我已经实现了 Spring Data Repositories,它使用注释扩展 MongoRepository@RepositoryRestResource
以将它们标记为 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!"
}
另外,我为每个存储库配置了两个数据库。
应用程序.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();
}
}
这里可能出了什么问题?