Polishing

This commit is contained in:
Juergen Hoeller
2018-07-24 15:17:33 +02:00
parent 484addb4f8
commit 2ae2249842
4 changed files with 37 additions and 32 deletions

View File

@@ -31,9 +31,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
@@ -146,7 +144,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
private final Set<Class<?>> ignoredDependencyInterfaces = new HashSet<Class<?>>();
/** Cache of unfinished FactoryBean instances: FactoryBean name --> BeanWrapper */
private final Map<String, BeanWrapper> factoryBeanInstanceCache =
private final ConcurrentMap<String, BeanWrapper> factoryBeanInstanceCache =
new ConcurrentHashMap<String, BeanWrapper>(16);
/** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */
@@ -1422,7 +1420,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
*/
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) {
List<PropertyDescriptor> pds =
new LinkedList<PropertyDescriptor>(Arrays.asList(bw.getPropertyDescriptors()));
new ArrayList<PropertyDescriptor>(Arrays.asList(bw.getPropertyDescriptors()));
for (Iterator<PropertyDescriptor> it = pds.iterator(); it.hasNext();) {
PropertyDescriptor pd = it.next();
if (isExcludedFromDependencyCheck(pd)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -45,7 +45,7 @@ import static org.junit.Assert.*;
/**
* Unit tests for {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor}
* processing the JSR-303 {@link javax.inject.Inject} annotation.
* processing the JSR-330 {@link javax.inject.Inject} annotation.
*
* @author Juergen Hoeller
* @since 3.0
@@ -548,11 +548,9 @@ public class InjectAnnotationBeanPostProcessorTests {
}
/**
* Verifies that a dependency on a {@link org.springframework.beans.factory.FactoryBean} can be autowired via
* {@link org.springframework.beans.factory.annotation.Autowired @Inject}, specifically addressing the JIRA issue
* raised in <a
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-4040"
* target="_blank">SPR-4040</a>.
* Verifies that a dependency on a {@link org.springframework.beans.factory.FactoryBean}
* can be autowired via {@link org.springframework.beans.factory.annotation.Autowired @Inject},
* specifically addressing SPR-4040.
*/
@Test
public void testBeanAutowiredWithFactoryBean() {
@@ -1259,7 +1257,7 @@ public class InjectAnnotationBeanPostProcessorTests {
public static class StringFactoryBean implements FactoryBean<String> {
@Override
public String getObject() throws Exception {
public String getObject() {
return "";
}
@@ -1291,8 +1289,8 @@ public class InjectAnnotationBeanPostProcessorTests {
private Optional<TestBean> testBean;
@Inject
public void setTestBean(Optional<TestBean> testBeanFactory) {
this.testBean = testBeanFactory;
public void setTestBean(Optional<TestBean> testBean) {
this.testBean = testBean;
}
public Optional<TestBean> getTestBean() {
@@ -1317,8 +1315,8 @@ public class InjectAnnotationBeanPostProcessorTests {
private Optional<List<TestBean>> testBean;
@Inject
public void setTestBean(Optional<List<TestBean>> testBeanFactory) {
this.testBean = testBeanFactory;
public void setTestBean(Optional<List<TestBean>> testBean) {
this.testBean = testBean;
}
public Optional<List<TestBean>> getTestBean() {
@@ -1343,8 +1341,8 @@ public class InjectAnnotationBeanPostProcessorTests {
private Provider<Optional<TestBean>> testBean;
@Inject
public void setTestBean(Provider<Optional<TestBean>> testBeanFactory) {
this.testBean = testBeanFactory;
public void setTestBean(Provider<Optional<TestBean>> testBean) {
this.testBean = testBean;
}
public Optional<TestBean> getTestBean() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
* invocation context.
*
* @author Stephane Nicoll
* @author Juergen Hoeller
* @since 4.1
*/
public abstract class AbstractCacheResolver implements CacheResolver, InitializingBean {
@@ -38,9 +39,17 @@ public abstract class AbstractCacheResolver implements CacheResolver, Initializi
private CacheManager cacheManager;
/**
* Construct a new {@code AbstractCacheResolver}.
* @see #setCacheManager
*/
protected AbstractCacheResolver() {
}
/**
* Construct a new {@code AbstractCacheResolver} for the given {@link CacheManager}.
* @param cacheManager the CacheManager to use
*/
protected AbstractCacheResolver(CacheManager cacheManager) {
this.cacheManager = cacheManager;
}
@@ -72,18 +81,16 @@ public abstract class AbstractCacheResolver implements CacheResolver, Initializi
if (cacheNames == null) {
return Collections.emptyList();
}
else {
Collection<Cache> result = new ArrayList<Cache>();
for (String cacheName : cacheNames) {
Cache cache = getCacheManager().getCache(cacheName);
if (cache == null) {
throw new IllegalArgumentException("Cannot find cache named '" +
cacheName + "' for " + context.getOperation());
}
result.add(cache);
Collection<Cache> result = new ArrayList<Cache>(cacheNames.size());
for (String cacheName : cacheNames) {
Cache cache = getCacheManager().getCache(cacheName);
if (cache == null) {
throw new IllegalArgumentException("Cannot find cache named '" +
cacheName + "' for " + context.getOperation());
}
return result;
result.add(cache);
}
return result;
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
@@ -118,8 +119,9 @@ public class OkHttp3ClientHttpRequestFactory
public void destroy() throws IOException {
if (this.defaultClient) {
// Clean up the client if we created it in the constructor
if (this.client.cache() != null) {
this.client.cache().close();
Cache cache = this.client.cache();
if (cache != null) {
cache.close();
}
this.client.dispatcher().executorService().shutdown();
}