spring - 如何禁用 RepositoryRestHandlerMapping 和 EndpointHandlerMapping?

标签 spring spring-mvc spring-boot spring-data-jpa spring-hateoas

我目前正在使用 Spring Boot、Hibernate 和 Spring-HATEOAS 构建一个带有 REST 接口(interface)的应用程序。我的数据模型被定义为带有 @Entity 注释的 bean,我正在使用 Spring 的功能来自动设置 Hibernate 存储库(创建扩展 PagingAndSortingRepository 的接口(interface))。我的应用程序完全是注释驱动的,即我没有 web.xml 而是使用 Spring 注释配置所有内容,例如 @Configuration@Bean等,并在 SpringApplication.run(MyApp.class, args);

的帮助下从我的 main 方法启动应用程序

这很好用,但是使用这种方法,会创建一个 RepositoryRestHandlerMappingEndpointHandlerMapping。这些创建了一堆我不需要也不想要的资源。我实现了自己的 Controller ,因为它们需要做的不仅仅是标准逻辑。

如何防止这种默认行为并禁用这些映射?

最佳答案

在您的主类中排除 RepositoryRestMvcAutoConfiguration。

@EnableAutoConfiguration(exclude = RepositoryRestMvcAutoConfiguration.class)

关于spring - 如何禁用 RepositoryRestHandlerMapping 和 EndpointHandlerMapping?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26739346/

相关文章:

java - 如何使用 Spring MVC 在 session 范围内声明变量

java - Spring CORS 设置

java - 应用 @ResponseBody 时出现循环 View 路径错误

java - 在 Spring Boot 2.0.4 中从 http 重定向到 https

java - 在 Zuul 预过滤器中修改请求正文不起作用

spring - 如何在 Spring-Boot 项目中编辑 Hibernate 设置?

java - Spring Security 错误凭证异常

spring-boot - Eureka 客户端异常 com.netflix.discovery.shared.transport.TransportException : Cannot execute request on any known server

java - 尝试将 JSON 数据发布到 Spring Controller ..根本不起作用

mysql - 由 : java. sql.SQLException 引起:字段 'customerNumber' 没有默认值 - hibernate 和 jpa