我目前正在使用 Spring Boot、Hibernate 和 Spring-HATEOAS 构建一个带有 REST 接口(interface)的应用程序。我的数据模型被定义为带有 @Entity
注释的 bean,我正在使用 Spring 的功能来自动设置 Hibernate 存储库(创建扩展 PagingAndSortingRepository
的接口(interface))。我的应用程序完全是注释驱动的,即我没有 web.xml
而是使用 Spring 注释配置所有内容,例如 @Configuration
、@Bean
等,并在 SpringApplication.run(MyApp.class, args);
main
方法启动应用程序
这很好用,但是使用这种方法,会创建一个 RepositoryRestHandlerMapping
和 EndpointHandlerMapping
。这些创建了一堆我不需要也不想要的资源。我实现了自己的 Controller ,因为它们需要做的不仅仅是标准逻辑。
如何防止这种默认行为并禁用这些映射?
最佳答案
在您的主类中排除 RepositoryRestMvcAutoConfiguration。
@EnableAutoConfiguration(exclude = RepositoryRestMvcAutoConfiguration.class)
关于spring - 如何禁用 RepositoryRestHandlerMapping 和 EndpointHandlerMapping?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26739346/