HypermediaAutoConfiguration should back off when Spring MVC absent

Fixes gh-19392
pull/19690/head
Madhura Bhave 5 years ago
parent 87dd11502a
commit 82dc7bcc90

@ -36,6 +36,7 @@ import org.springframework.hateoas.config.EnableHypermediaSupport;
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
import org.springframework.plugin.core.Plugin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring HATEOAS's
@ -47,7 +48,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
* @since 1.1.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ EntityModel.class, RequestMapping.class, Plugin.class })
@ConditionalOnClass({ EntityModel.class, RequestMapping.class, RequestMappingHandlerAdapter.class, Plugin.class })
@ConditionalOnWebApplication
@AutoConfigureAfter({ WebMvcAutoConfiguration.class, JacksonAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class, RepositoryRestMvcAutoConfiguration.class })

@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguratio
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.hateoas.MediaTypes;
@ -54,6 +55,12 @@ class HypermediaAutoConfigurationTests {
private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withUserConfiguration(BaseConfig.class);
@Test
void autoConfigurationWhenSpringMvcNotOnClasspathShouldBackOff() {
this.contextRunner.withClassLoader(new FilteredClassLoader(RequestMappingHandlerAdapter.class))
.run((context) -> assertThat(context.getBeansOfType(HypermediaConfiguration.class)).isEmpty());
}
@Test
void linkDiscoverersCreated() {
this.contextRunner.run((context) -> {

Loading…
Cancel
Save