Skip to content

Commit ad94774

Browse files
committed
Simplify HypermediaAutoConfiguration
Spring HATEOAS already properly decorates ObjectMappers with @EnableHypermediaSupport. This removes unnecessary calls and decouples Boot from internal Spring HATEOAS APIs at the same time. Resolves gh-3882
1 parent cb4e709 commit ad94774

File tree

3 files changed

+0
-84
lines changed

3 files changed

+0
-84
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HateoasProperties.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@
1616

1717
package org.springframework.boot.autoconfigure.hateoas;
1818

19-
import javax.annotation.PostConstruct;
20-
2119
import org.springframework.beans.BeansException;
2220
import org.springframework.beans.factory.BeanFactory;
2321
import org.springframework.beans.factory.BeanFactoryAware;
2422
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
25-
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.beans.factory.annotation.Qualifier;
2723
import org.springframework.beans.factory.config.BeanPostProcessor;
2824
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2925
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -33,18 +29,14 @@
3329
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
3430
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
3531
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
36-
import org.springframework.boot.context.properties.EnableConfigurationProperties;
3732
import org.springframework.context.annotation.Bean;
3833
import org.springframework.context.annotation.Configuration;
3934
import org.springframework.hateoas.EntityLinks;
4035
import org.springframework.hateoas.LinkDiscoverers;
41-
import org.springframework.hateoas.RelProvider;
4236
import org.springframework.hateoas.Resource;
4337
import org.springframework.hateoas.config.EnableEntityLinks;
4438
import org.springframework.hateoas.config.EnableHypermediaSupport;
4539
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
46-
import org.springframework.hateoas.hal.CurieProvider;
47-
import org.springframework.hateoas.hal.Jackson2HalModule;
4840
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
4941
import org.springframework.plugin.core.Plugin;
5042
import org.springframework.web.bind.annotation.RequestMapping;
@@ -65,7 +57,6 @@
6557
@ConditionalOnWebApplication
6658
@AutoConfigureAfter({ WebMvcAutoConfiguration.class, JacksonAutoConfiguration.class,
6759
HttpMessageConvertersAutoConfiguration.class })
68-
@EnableConfigurationProperties(HateoasProperties.class)
6960
public class HypermediaAutoConfiguration {
7061

7162
@Configuration
@@ -76,35 +67,6 @@ protected static class HypermediaConfiguration {
7667
@ConditionalOnClass({ Jackson2ObjectMapperBuilder.class, ObjectMapper.class })
7768
protected static class HalObjectMapperConfiguration {
7869

79-
@Autowired
80-
private HateoasProperties hateoasProperties;
81-
82-
@Autowired(required = false)
83-
private CurieProvider curieProvider;
84-
85-
@Autowired
86-
@Qualifier("_relProvider")
87-
private RelProvider relProvider;
88-
89-
@Autowired(required = false)
90-
private ObjectMapper primaryObjectMapper;
91-
92-
@PostConstruct
93-
public void configurePrimaryObjectMapper() {
94-
if (this.primaryObjectMapper != null
95-
&& this.hateoasProperties.isApplyToPrimaryObjectMapper()) {
96-
registerHalModule(this.primaryObjectMapper);
97-
}
98-
}
99-
100-
private void registerHalModule(ObjectMapper objectMapper) {
101-
objectMapper.registerModule(new Jackson2HalModule());
102-
Jackson2HalModule.HalHandlerInstantiator instantiator = new Jackson2HalModule.HalHandlerInstantiator(
103-
HalObjectMapperConfiguration.this.relProvider,
104-
HalObjectMapperConfiguration.this.curieProvider);
105-
objectMapper.setHandlerInstantiator(instantiator);
106-
}
107-
10870
@Bean
10971
public static HalObjectMapperConfigurer halObjectMapperConfigurer() {
11072
return new HalObjectMapperConfigurer();

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ content into your application; rather pick only the properties that you need.
110110
multipart.max-file-size=1Mb # Max file size.
111111
multipart.max-request-size=10Mb # Max request size.
112112
113-
# SPRING HATEOAS ({sc-spring-boot-autoconfigure}/hateoas/HateoasProperties.{sc-ext}[HateoasProperties])
114-
spring.hateoas.apply-to-primary-object-mapper=true # if the primary mapper should also be configured
115-
116113
# HTTP encoding ({sc-spring-boot-autoconfigure}/web/HttpEncodingProperties.{sc-ext}[HttpEncodingProperties])
117114
spring.http.encoding.charset=UTF-8 # the encoding of HTTP requests/responses
118115
spring.http.encoding.enabled=true # enable http encoding support

0 commit comments

Comments
 (0)