Add auto-configuration for @EnableHypermediaSupport
If Spring HATEOAS is on the class path, then @EnableHypermediaSupport will be auto-configured with HAL support.
This commit is contained in:
		
							parent
							
								
									e8e59ea657
								
							
						
					
					
						commit
						6ad7257baf
					
				|  | @ -136,6 +136,11 @@ | |||
| 			<artifactId>spring-data-redis</artifactId> | ||||
| 			<optional>true</optional> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework.hateoas</groupId> | ||||
| 			<artifactId>spring-hateoas</artifactId> | ||||
| 			<optional>true</optional> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>com.lambdaworks</groupId> | ||||
| 			<artifactId>lettuce</artifactId> | ||||
|  | @ -229,5 +234,10 @@ | |||
| 			<artifactId>slf4j-jdk14</artifactId> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.springframework.plugin</groupId> | ||||
| 			<artifactId>spring-plugin-core</artifactId> | ||||
| 			<scope>test</scope> | ||||
| 		</dependency> | ||||
| 	</dependencies> | ||||
| </project> | ||||
|  |  | |||
|  | @ -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 { | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -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,\ | ||||
|  |  | |||
|  | @ -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)); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -88,6 +88,7 @@ | |||
| 		<spring-data-redis.version>1.1.1.RELEASE</spring-data-redis.version> | ||||
| 		<spring-data-rest.version>2.0.2.RELEASE</spring-data-rest.version> | ||||
| 		<spring-hateoas.version>0.9.0.RELEASE</spring-hateoas.version> | ||||
| 		<spring-plugin.version>1.0.0.RELEASE</spring-plugin.version> | ||||
| 		<spring-rabbit.version>1.2.2.RELEASE</spring-rabbit.version> | ||||
| 		<spring-mobile.version>1.1.1.RELEASE</spring-mobile.version> | ||||
| 		<spring-security.version>3.2.3.RELEASE</spring-security.version> | ||||
|  | @ -542,6 +543,11 @@ | |||
| 				<artifactId>spring-hateoas</artifactId> | ||||
| 				<version>${spring-hateoas.version}</version> | ||||
| 			</dependency> | ||||
| 			<dependency> | ||||
| 				<groupId>org.springframework.plugin</groupId> | ||||
| 				<artifactId>spring-plugin-core</artifactId> | ||||
| 				<version>${spring-plugin.version}</version> | ||||
| 			</dependency> | ||||
| 			<dependency> | ||||
| 				<groupId>org.springframework.data</groupId> | ||||
| 				<artifactId>spring-data-rest-webmvc</artifactId> | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue