Polish
This commit is contained in:
@@ -116,26 +116,14 @@ abstract class BeanTypeRegistry {
|
||||
definition.getFactoryMethodName());
|
||||
Class<?> generic = ResolvableType.forMethodReturnType(method)
|
||||
.as(FactoryBean.class).resolveGeneric();
|
||||
if (generic == null || generic.equals(Object.class)) {
|
||||
generic = determineTypeFromDefinitionAttribute(factoryDefinition);
|
||||
if ((generic == null || generic.equals(Object.class))
|
||||
&& definition.hasAttribute(FACTORY_BEAN_OBJECT_TYPE)) {
|
||||
generic = getTypeFromAttribute(definition
|
||||
.getAttribute(FACTORY_BEAN_OBJECT_TYPE));
|
||||
}
|
||||
return generic;
|
||||
}
|
||||
|
||||
private Class<?> determineTypeFromDefinitionAttribute(BeanDefinition definition)
|
||||
throws ClassNotFoundException, LinkageError {
|
||||
if (definition.hasAttribute(FACTORY_BEAN_OBJECT_TYPE)) {
|
||||
Object attributeObject = definition.getAttribute(FACTORY_BEAN_OBJECT_TYPE);
|
||||
if (attributeObject instanceof Class<?>) {
|
||||
return (Class<?>) attributeObject;
|
||||
}
|
||||
else if (attributeObject instanceof String) {
|
||||
return ClassUtils.forName((String) attributeObject, null);
|
||||
}
|
||||
}
|
||||
return Object.class;
|
||||
}
|
||||
|
||||
private Class<?> getDirectFactoryBeanGeneric(
|
||||
ConfigurableListableBeanFactory beanFactory, BeanDefinition definition,
|
||||
String name) throws ClassNotFoundException, LinkageError {
|
||||
@@ -143,12 +131,25 @@ abstract class BeanTypeRegistry {
|
||||
beanFactory.getBeanClassLoader());
|
||||
Class<?> generic = ResolvableType.forClass(factoryBeanClass)
|
||||
.as(FactoryBean.class).resolveGeneric();
|
||||
if (generic == null || generic.equals(Object.class)) {
|
||||
generic = determineTypeFromDefinitionAttribute(definition);
|
||||
if ((generic == null || generic.equals(Object.class))
|
||||
&& definition.hasAttribute(FACTORY_BEAN_OBJECT_TYPE)) {
|
||||
generic = getTypeFromAttribute(definition
|
||||
.getAttribute(FACTORY_BEAN_OBJECT_TYPE));
|
||||
}
|
||||
return generic;
|
||||
}
|
||||
|
||||
private Class<?> getTypeFromAttribute(Object attribute)
|
||||
throws ClassNotFoundException, LinkageError {
|
||||
if (attribute instanceof Class<?>) {
|
||||
return (Class<?>) attribute;
|
||||
}
|
||||
if (attribute instanceof String) {
|
||||
return ClassUtils.forName((String) attribute, null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to get the {@link BeanTypeRegistry} for a given {@link BeanFactory}.
|
||||
* @param beanFactory the source bean factory
|
||||
|
||||
@@ -163,7 +163,7 @@ public class GzipFilterProperties {
|
||||
}
|
||||
|
||||
public List<MimeType> getExcludedMimeTypes() {
|
||||
return excludedMimeTypes;
|
||||
return this.excludedMimeTypes;
|
||||
}
|
||||
|
||||
public void setExcludedMimeTypes(List<MimeType> excludedMimeTypes) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
@@ -51,9 +51,7 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
|
||||
@Test
|
||||
public void testDefaultRepositoryConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
addElasticsearchProperties(this.context);
|
||||
this.context.register(TestConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class,
|
||||
@@ -67,9 +65,7 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
|
||||
@Test
|
||||
public void testNoRepositoryConfiguration() throws Exception {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
addElasticsearchProperties(this.context);
|
||||
this.context.register(EmptyConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class,
|
||||
@@ -82,9 +78,7 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
|
||||
@Test
|
||||
public void doesNotTriggerDefaultRepositoryDetectionIfCustomized() {
|
||||
this.context = new AnnotationConfigApplicationContext();
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
addElasticsearchProperties(this.context);
|
||||
this.context.register(CustomizedConfiguration.class,
|
||||
ElasticsearchAutoConfiguration.class,
|
||||
ElasticsearchRepositoriesAutoConfiguration.class,
|
||||
@@ -94,6 +88,12 @@ public class ElasticsearchRepositoriesAutoConfigurationTests {
|
||||
assertNotNull(this.context.getBean(CityElasticsearchDbRepository.class));
|
||||
}
|
||||
|
||||
private void addElasticsearchProperties(AnnotationConfigApplicationContext context) {
|
||||
EnvironmentTestUtils.addEnvironment(context,
|
||||
"spring.data.elasticsearch.properties.path.data:target/data",
|
||||
"spring.data.elasticsearch.properties.path.logs:target/logs");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@TestAutoConfigurationPackage(City.class)
|
||||
protected static class TestConfiguration {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2015 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.
|
||||
@@ -54,4 +54,5 @@ public class ElasticsearchDataAutoConfigurationTests {
|
||||
assertEquals(1,
|
||||
this.context.getBeanNamesForType(ElasticsearchTemplate.class).length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user