如何解决@RepositoryRestResource 每次重新启动应用程序时都会更改 url
我有一个扩展 JpaRepository
和 NameRepositoryCustom
的存储库接口。
我的存储库用 @RepositoryRestRessource(collectionResourceRel="pathname",path="pathname")
注释。
我遇到的问题是,我的应用程序每重新启动一次,存储库的 URL 就会更改,因此我无法在我定义的 URL 下找到存储库的公开数据,并且某些功能(例如存储库搜索)未公开也不再使用 API。
“NameRepositroyCustom”用于搜索功能,该功能使用另一个存储库为前端的搜索栏实现 JPA Criteria Api 规范。
有没有人有解决方案?唯一标注为 @RepositoryRestRessource
的存储库是实现所有其他存储库的主存储库。 NameRepositorySpec
带有 @Repository
注释,这可能是原因吗?
编辑:我以代码为例来阐明上述类和接口之间的关系。 这是与持久化在数据库中的实体相关的基本存储库:
@RepositoryRestResource(collectionRessourceRel = "enitynames",path = "entitynames")
public interface EntitynameRepository extends JpaRepository<Entityname,Long>,EntitynameRepositoryCustom{
//custom methods in here
}
这是自定义存储库:
public interface EntitynameRepositoryCustom {
Page<Entityname> search(String exampleParam1,String exampleParam2,Pageable pageable);
}
这是自定义存储库的实现:
public class EntitynameRepositoryCustomImpl implements EntitynameRepositoryCustom{
@Autowired
EntityManager em;
@Autowired
EntitynameRepositorySpec entitynameRepositorySpec;
Specification<Entityname> querySpecification = null;
@Override
public Page<Entityname> search(String exampleParam1,Pageable pageable) {
//Code here uses the criteria builder and Specification to generate a custom query with optional parameters
CriteriaBuilder cb= em.getCriteriaBuilder();
CriteriaQuery<Entityname> cq = cb.createquery(Entityname.class);
//Code below is done for every passed in parameter
if(exampleParam1 != null){
Specification<Entityname> param1Specification = EntitynameSpecification.likeParam1(exampleParam1);
querySpecification = Specification.where(param1Specification);
} else {
return null;
}
return entitynameRepositorySpec.findAll(specification,pageable);
}
}
这是规范存储库:
public interface EntitynameRepositorySpec extends JpaRepository<Entityname,JpaSpecificationExecutor<Entityname>{
}
这是规范的实现:
public class EntitynameSpecification {
public static Specification<Entityname> likeExampleParam1(String exampleParam1){
if(exampleParam1 == null){
return null;
}
return(root,query,cb) -> {
reutrn cb.like(root.get("fieldname"),"%"+ exampleParam1 + "%");
};
}
}
与我的示例相比,存储库的 URL 更改为实体名称的一部分,类似于: entityname has URL: /entityname 如果发生错误,URL 将更改为 /name。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。