#1021 - Tweak setup of @EnableEntityLinks to make sure it only runs on Spring WebMVC.
We now clearly separate the beans registered by configuration backing @EnableEntityLinks into the ones that depend on Spring MVC being used and commonly shared ones. Tweaked the setup of @EnableHypermediaSupport to rather include the individual configuration classes instead of using @EnableEntityLinks directly as that would always pull WebMVC specific components.
This commit is contained in:
@@ -29,13 +29,13 @@ import org.springframework.hateoas.server.core.DelegatingEntityLinks;
|
||||
/**
|
||||
* Enables the collection of {@link LinkBuilder} instances from the application context. All found ones will be exposed
|
||||
* through an instance of {@link DelegatingEntityLinks}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Inherited
|
||||
@Documented
|
||||
@Import(EntityLinksConfiguration.class)
|
||||
@Import({ EntityLinksConfiguration.class, WebMvcEntityLinksConfiguration.class })
|
||||
public @interface EnableEntityLinks {
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.springframework.web.reactive.function.client.WebClient;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@Documented
|
||||
@EnableEntityLinks
|
||||
@Import({ HypermediaConfigurationImportSelector.class, HateoasConfiguration.class, WebStackImportSelector.class })
|
||||
public @interface EnableHypermediaSupport {
|
||||
|
||||
|
||||
@@ -15,18 +15,14 @@
|
||||
*/
|
||||
package org.springframework.hateoas.config;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.server.core.ControllerEntityLinksFactoryBean;
|
||||
import org.springframework.hateoas.server.core.DelegatingEntityLinks;
|
||||
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilderFactory;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.plugin.core.support.PluginRegistryFactoryBean;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* Spring configuration to register a {@link PluginRegistry} for {@link EntityLinks}.
|
||||
@@ -53,14 +49,4 @@ class EntityLinksConfiguration {
|
||||
DelegatingEntityLinks delegatingEntityLinks(PluginRegistry<EntityLinks, Class<?>> entityLinksPluginRegistry) {
|
||||
return new DelegatingEntityLinks(entityLinksPluginRegistry);
|
||||
}
|
||||
|
||||
@Bean
|
||||
ControllerEntityLinksFactoryBean webMvcEntityLinks(ObjectProvider<WebMvcLinkBuilderFactory> linkBuilderFactory) {
|
||||
|
||||
ControllerEntityLinksFactoryBean factory = new ControllerEntityLinksFactoryBean();
|
||||
factory.setAnnotation(Controller.class);
|
||||
factory.setLinkBuilderFactory(linkBuilderFactory.getIfAvailable(WebMvcLinkBuilderFactory::new));
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.hateoas.config;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.support.MessageSourceAccessor;
|
||||
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
||||
@@ -44,6 +45,7 @@ import org.springframework.util.ClassUtils;
|
||||
* @since 0.19
|
||||
*/
|
||||
@Configuration
|
||||
@Import(EntityLinksConfiguration.class)
|
||||
@EnablePluginRegistries({ LinkDiscoverer.class })
|
||||
class HateoasConfiguration {
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
package org.springframework.hateoas.config;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.hateoas.server.EntityLinks;
|
||||
import org.springframework.hateoas.server.core.ControllerEntityLinksFactoryBean;
|
||||
import org.springframework.hateoas.server.mvc.WebMvcLinkBuilderFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* Spring WebMVC specific bean definitions to support {@link EntityLinks}.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
class WebMvcEntityLinksConfiguration {
|
||||
|
||||
@Bean
|
||||
ControllerEntityLinksFactoryBean webMvcEntityLinks(ObjectProvider<WebMvcLinkBuilderFactory> linkBuilderFactory) {
|
||||
|
||||
ControllerEntityLinksFactoryBean factory = new ControllerEntityLinksFactoryBean();
|
||||
factory.setAnnotation(Controller.class);
|
||||
factory.setLinkBuilderFactory(linkBuilderFactory.getIfAvailable(WebMvcLinkBuilderFactory::new));
|
||||
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.hateoas.RepresentationModel;
|
||||
import org.springframework.hateoas.server.RepresentationModelProcessor;
|
||||
import org.springframework.hateoas.server.mvc.RepresentationModelProcessorHandlerMethodReturnValueHandler;
|
||||
@@ -50,6 +51,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
@Configuration
|
||||
@Import(WebMvcEntityLinksConfiguration.class)
|
||||
class WebMvcHateoasConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user