Use constructor injection in SpringBootRepositoryRestConfigurer

Closes gh-25819
pull/26153/head
Andy Wilkinson 4 years ago
parent d1aaee46bb
commit 403e747c46

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.data.rest;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@ -30,6 +31,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Data Rest's MVC
@ -56,8 +58,9 @@ import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguratio
public class RepositoryRestMvcAutoConfiguration {
@Bean
public SpringBootRepositoryRestConfigurer springBootRepositoryRestConfigurer() {
return new SpringBootRepositoryRestConfigurer();
public SpringBootRepositoryRestConfigurer springBootRepositoryRestConfigurer(
ObjectProvider<Jackson2ObjectMapperBuilder> objectMapperBuilder, RepositoryRestProperties properties) {
return new SpringBootRepositoryRestConfigurer(objectMapperBuilder.getIfAvailable(), properties);
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -38,10 +38,16 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry;
class SpringBootRepositoryRestConfigurer implements RepositoryRestConfigurer {
@Autowired(required = false)
private Jackson2ObjectMapperBuilder objectMapperBuilder;
private final Jackson2ObjectMapperBuilder objectMapperBuilder;
@Autowired
private RepositoryRestProperties properties;
private final RepositoryRestProperties properties;
SpringBootRepositoryRestConfigurer(Jackson2ObjectMapperBuilder objectMapperBuilder,
RepositoryRestProperties properties) {
this.objectMapperBuilder = objectMapperBuilder;
this.properties = properties;
}
@Override
@SuppressWarnings("deprecation")

Loading…
Cancel
Save