Create spring-boot-hateoas module

Issue: 46117
This commit is contained in:
Andy Wilkinson 2025-03-26 20:33:22 +00:00 committed by Phillip Webb
parent 4c0839f516
commit 313b328508
17 changed files with 77 additions and 37 deletions

View File

@ -81,6 +81,7 @@ include "spring-boot-project:spring-boot-freemarker"
include "spring-boot-project:spring-boot-groovy-templates"
include "spring-boot-project:spring-boot-gson"
include "spring-boot-project:spring-boot-h2console"
include "spring-boot-project:spring-boot-hateoas"
include "spring-boot-project:spring-boot-hazelcast"
include "spring-boot-project:spring-boot-integration"
include "spring-boot-project:spring-boot-jackson"

View File

@ -163,6 +163,7 @@ dependencies {
optional("org.springframework.session:spring-session-core")
optional("redis.clients:jedis")
testImplementation(project(":spring-boot-project:spring-boot-hateoas"))
testImplementation(project(":spring-boot-project:spring-boot-test"))
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation(testFixtures(project(":spring-boot-project:spring-boot")))

View File

@ -32,11 +32,11 @@ import org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandl
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.hateoas.autoconfigure.HypermediaAutoConfiguration;
import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;

View File

@ -35,7 +35,6 @@ org.springframework.boot.autoconfigure.graphql.rsocket.RSocketGraphQlClientAutoC
org.springframework.boot.autoconfigure.graphql.security.GraphQlWebFluxSecurityAutoConfiguration
org.springframework.boot.autoconfigure.graphql.security.GraphQlWebMvcSecurityAutoConfiguration
org.springframework.boot.autoconfigure.graphql.servlet.GraphQlWebMvcAutoConfiguration
org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration
org.springframework.boot.autoconfigure.http.client.HttpClientAutoConfiguration
org.springframework.boot.autoconfigure.http.client.service.HttpServiceClientAutoConfiguration

View File

@ -2007,6 +2007,7 @@ bom {
"spring-boot-groovy-templates",
"spring-boot-gson",
"spring-boot-h2console",
"spring-boot-hateoas",
"spring-boot-hazelcast",
"spring-boot-integration",
"spring-boot-jackson",

View File

@ -93,6 +93,7 @@ dependencies {
autoConfiguration(project(path: ":spring-boot-project:spring-boot-freemarker", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-gson", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-h2console", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-hateoas", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-hazelcast", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-integration", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "autoConfigurationMetadata"))
@ -143,6 +144,7 @@ dependencies {
configurationProperties(project(path: ":spring-boot-project:spring-boot-freemarker", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-gson", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-h2console", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-hateoas", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-hazelcast", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-integration", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "configurationPropertiesMetadata"))

View File

@ -0,0 +1,42 @@
/*
* Copyright 2012-present 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "java-library"
id "org.springframework.boot.auto-configuration"
id "org.springframework.boot.configuration-properties"
id "org.springframework.boot.deployed"
id "org.springframework.boot.optional-dependencies"
}
description = "Spring Boot Hateoas"
dependencies {
api(project(":spring-boot-project:spring-boot"))
api("org.springframework.hateoas:spring-hateoas")
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("org.springframework:spring-webmvc")
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
testImplementation(project(":spring-boot-project:spring-boot-test"))
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation("jakarta.servlet:jakarta.servlet-api")
testRuntimeOnly("ch.qos.logback:logback-classic")
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.hateoas;
package org.springframework.boot.hateoas.autoconfigure;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ -23,7 +23,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
*
* @author Phillip Webb
* @author Andy Wilkinson
* @since 1.2.1
* @since 4.0.0
*/
@ConfigurationProperties("spring.hateoas")
public class HateoasProperties {

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.hateoas;
package org.springframework.boot.hateoas.autoconfigure;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -24,9 +24,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProp
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.data.rest.RepositoryRestMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -47,20 +44,17 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
* @author Roy Clarkson
* @author Oliver Gierke
* @author Andy Wilkinson
* @since 1.1.0
* @since 4.0.0
*/
@AutoConfiguration(
after = { WebMvcAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class,
RepositoryRestMvcAutoConfiguration.class },
afterName = "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration")
@ConditionalOnClass({ EntityModel.class, RequestMapping.class, RequestMappingHandlerAdapter.class, Plugin.class })
@AutoConfiguration
@ConditionalOnClass({ EntityModel.class, RequestMapping.class, RequestMappingHandlerAdapter.class, Plugin.class,
ObjectMapper.class })
@ConditionalOnWebApplication
@EnableConfigurationProperties(HateoasProperties.class)
public class HypermediaAutoConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnClass(name = "com.fasterxml.jackson.databind.ObjectMapper")
@ConditionalOnBooleanProperty(name = "spring.hateoas.use-hal-as-default-json-media-type", matchIfMissing = true)
HalConfiguration applicationJsonHalConfiguration() {
return new HalConfiguration().withMediaType(MediaType.APPLICATION_JSON);
@ -68,9 +62,8 @@ public class HypermediaAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingBean(LinkDiscoverers.class)
@ConditionalOnClass(ObjectMapper.class)
@EnableHypermediaSupport(type = HypermediaType.HAL)
protected static class HypermediaConfiguration {
static class HypermediaConfiguration {
}

View File

@ -17,4 +17,4 @@
/**
* Auto-configuration for Spring HATEOAS.
*/
package org.springframework.boot.autoconfigure.hateoas;
package org.springframework.boot.hateoas.autoconfigure;

View File

@ -0,0 +1,4 @@
{
"groups": [],
"properties": []
}

View File

@ -0,0 +1 @@
org.springframework.boot.hateoas.autoconfigure.HypermediaAutoConfiguration

View File

@ -14,17 +14,14 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.hateoas;
package org.springframework.boot.hateoas.autoconfigure;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration.HypermediaConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration;
import org.springframework.boot.hateoas.autoconfigure.HypermediaAutoConfiguration.HypermediaConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Configuration;
@ -38,6 +35,7 @@ import org.springframework.hateoas.mediatype.hal.HalLinkDiscoverer;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import static org.assertj.core.api.Assertions.assertThat;
@ -117,8 +115,8 @@ class HypermediaAutoConfigurationTests {
});
}
@ImportAutoConfiguration({ HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class,
JacksonAutoConfiguration.class, HypermediaAutoConfiguration.class })
@EnableWebMvc
@ImportAutoConfiguration(HypermediaAutoConfiguration.class)
static class BaseConfig {
}

View File

@ -14,13 +14,11 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.hateoas;
package org.springframework.boot.hateoas.autoconfigure;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
import org.springframework.mock.web.MockServletContext;
@ -43,8 +41,7 @@ class HypermediaAutoConfigurationWithoutJacksonTests {
this.context.refresh();
}
@ImportAutoConfiguration({ HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class,
HypermediaAutoConfiguration.class })
@ImportAutoConfiguration(HypermediaAutoConfiguration.class)
static class BaseConfig {
}

View File

@ -21,6 +21,6 @@ plugins {
description = "Starter for building hypermedia-based RESTful web application with Spring MVC and Spring HATEOAS"
dependencies {
api(project(":spring-boot-project:spring-boot-hateoas"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
api("org.springframework.hateoas:spring-hateoas")
}

View File

@ -61,6 +61,7 @@ dependencies {
optional(project(":spring-boot-project:spring-boot-elasticsearch"))
optional(project(":spring-boot-project:spring-boot-flyway"))
optional(project(":spring-boot-project:spring-boot-groovy-templates"))
optional(project(":spring-boot-project:spring-boot-hateoas"))
optional(project(":spring-boot-project:spring-boot-jackson"))
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional(project(":spring-boot-project:spring-boot-jooq"))

View File

@ -1,14 +1,14 @@
# AutoConfigureWebMvc auto-configuration imports
optional:org.springframework.boot.freemarker.autoconfigure.FreeMarkerAutoConfiguration
optional:org.springframework.boot.groovy.template.autoconfigure.GroovyTemplateAutoConfiguration
optional:org.springframework.boot.hateoas.autoconfigure.HypermediaAutoConfiguration
optional:org.springframework.boot.mustache.autoconfigure.MustacheAutoConfiguration
optional:org.springframework.boot.thymeleaf.autoconfigure.ThymeleafAutoConfiguration
optional:org.springframework.boot.validation.autoconfigure.ValidationAutoConfiguration
org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration
org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration
optional:org.springframework.boot.freemarker.autoconfigure.FreeMarkerAutoConfiguration
org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration
optional:org.springframework.boot.mustache.autoconfigure.MustacheAutoConfiguration
org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration
optional:org.springframework.boot.thymeleaf.autoconfigure.ThymeleafAutoConfiguration
optional:org.springframework.boot.groovy.template.autoconfigure.GroovyTemplateAutoConfiguration
optional:org.springframework.boot.validation.autoconfigure.ValidationAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration