DATACMNS-475 - Added configuration class to auto-register GeoModule.
Added a JavaConfig class to declare a Spring bean for the newly introduced GeoModule. @EnableSpringDataWebSupport automatically registers this config class in case Jackson is on the classpath. This comes in handy in combination with Spring Boot which auto-registers all global Module beans with all global ObjectMappers.
This commit is contained in:
@@ -20,6 +20,8 @@ import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.ImportSelector;
|
||||
@@ -80,6 +82,7 @@ public @interface EnableSpringDataWebSupport {
|
||||
|
||||
// Don't make final to allow test cases faking this to false
|
||||
private static boolean HATEOAS_PRESENT = ClassUtils.isPresent("org.springframework.hateoas.Link", null);
|
||||
private static boolean JACKSON_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
@@ -87,8 +90,17 @@ public @interface EnableSpringDataWebSupport {
|
||||
*/
|
||||
@Override
|
||||
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
|
||||
return new String[] { HATEOAS_PRESENT ? HateoasAwareSpringDataWebConfiguration.class.getName()
|
||||
: SpringDataWebConfiguration.class.getName() };
|
||||
|
||||
List<String> imports = new ArrayList<String>();
|
||||
|
||||
imports.add(HATEOAS_PRESENT ? HateoasAwareSpringDataWebConfiguration.class.getName()
|
||||
: SpringDataWebConfiguration.class.getName());
|
||||
|
||||
if (JACKSON_PRESENT) {
|
||||
imports.add(SpringDataJacksonConfiguration.class.getName());
|
||||
}
|
||||
|
||||
return imports.toArray(new String[imports.size()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 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.data.web.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.geo.GeoModule;
|
||||
|
||||
/**
|
||||
* JavaConfig class to export Jackson specific configuration.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
public class SpringDataJacksonConfiguration {
|
||||
|
||||
@Bean
|
||||
public GeoModule jacksonGeoModule() {
|
||||
return new GeoModule();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user