diff --git a/spring-boot-autoconfigure/pom.xml b/spring-boot-autoconfigure/pom.xml index 1b21f651e43..f21289397d1 100644 --- a/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-autoconfigure/pom.xml @@ -136,6 +136,11 @@ spring-data-redis true + + org.springframework.hateoas + spring-hateoas + true + com.lambdaworks lettuce @@ -229,5 +234,10 @@ slf4j-jdk14 test + + org.springframework.plugin + spring-plugin-core + test + diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java new file mode 100644 index 00000000000..40b4fd0231b --- /dev/null +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfiguration.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2014 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 + * + * http://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.boot.autoconfigure.hateoas; + +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.hateoas.Resource; +import org.springframework.hateoas.config.EnableHypermediaSupport; +import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for Spring HATEOAS's + * {@link EnableHypermediaSupport}. + * + * @author Roy Clarkson + */ +@Configuration +@ConditionalOnClass(Resource.class) +@AutoConfigureAfter(WebMvcAutoConfiguration.class) +public class HypermediaAutoConfiguration { + + @Configuration + @EnableHypermediaSupport(type = HypermediaType.HAL) + @ConditionalOnWebApplication + protected static class HypermediaConfiguration { + + } + +} diff --git a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 5054c05cb6c..2983e7ee72c 100644 --- a/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -11,6 +11,7 @@ org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration,\ org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\ org.springframework.boot.autoconfigure.data.JpaRepositoriesAutoConfiguration,\ org.springframework.boot.autoconfigure.data.MongoRepositoriesAutoConfiguration,\ +org.springframework.boot.autoconfigure.hateoas.HypermediaAutoConfiguration,\ org.springframework.boot.autoconfigure.redis.RedisAutoConfiguration,\ org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,\ org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration,\ diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java new file mode 100644 index 00000000000..1b3a244eacf --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hateoas/HypermediaAutoConfigurationTests.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-2014 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 + * + * http://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.boot.autoconfigure.hateoas; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.Test; +import org.springframework.hateoas.LinkDiscoverer; +import org.springframework.hateoas.LinkDiscoverers; +import org.springframework.hateoas.MediaTypes; +import org.springframework.hateoas.hal.HalLinkDiscoverer; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; + +/** + * Tests for {@link HypermediaAutoConfiguration}. + * + * @author Roy Clarkson + */ +public class HypermediaAutoConfigurationTests { + + private AnnotationConfigWebApplicationContext context; + + @After + public void close() { + if (this.context != null) { + this.context.close(); + } + } + + @Test + public void linkDiscoverersCreated() throws Exception { + this.context = new AnnotationConfigWebApplicationContext(); + this.context.register(HypermediaAutoConfiguration.class); + this.context.refresh(); + LinkDiscoverers discoverers = this.context.getBean(LinkDiscoverers.class); + assertNotNull(discoverers); + LinkDiscoverer discoverer = discoverers.getLinkDiscovererFor(MediaTypes.HAL_JSON); + assertTrue(HalLinkDiscoverer.class.isInstance(discoverer)); + } + +} diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 957802c4eb3..e4b2e8128e9 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -88,6 +88,7 @@ 1.1.1.RELEASE 2.0.2.RELEASE 0.9.0.RELEASE + 1.0.0.RELEASE 1.2.2.RELEASE 1.1.1.RELEASE 3.2.3.RELEASE @@ -542,6 +543,11 @@ spring-hateoas ${spring-hateoas.version} + + org.springframework.plugin + spring-plugin-core + ${spring-plugin.version} + org.springframework.data spring-data-rest-webmvc