How to disable RepositoryRestHandlerMapping and EndpointHandlerMapping?

后端 未结 4 2201
轮回少年
轮回少年 2021-02-07 02:32

I am currently building an application with a REST interface, using Spring Boot, Hibernate and Spring-HATEOAS. My data model is defined as beans with @Entity annota

4条回答
  •  [愿得一人]
    2021-02-07 02:50

    I need the other REST functions, like @RestController annotation. But I found a feasible solution myself now:

    RepositoryRestHandlerMapping should not be disabled, but it is possible to disable exporting of repositories by annotating them with @RepositoryRestResource(exported = false). I did this with all my repositories and now, the wildcard resources are still installed, but no repositories are registered to resolve against them, making them effectively disappear. Trying to access such a resource gives a 404 as expected.

    Same for EndpointHandlerMapping, which comes from spring-boot-actuator and installs some endpoints like /info, /metrics etc. This is handy and should be present in a REST application; when I register my application with an Eureka server, it automatically generates links to some of these. To use this correctly, the endpoints can for example be configured via @Bean, like this:

    @Configuration
    public class InfoConfiguration {
    
        @Bean
        public InfoEndpoint infoEndpoint {
            Map info = ...
            return new InfoEndpoint(info);
        }
    }
    

    The info above is constant info, if there were info which is subject to change, one could override InfoEndpoint and supply a custom implementation of getAdditionalInfo().

提交回复
热议问题