From 5587262fcdd547b9ac92099ed0f5d3558ac985ce Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 27 Apr 2020 14:50:02 +0200 Subject: [PATCH] Polishing --- .../beans/factory/FactoryBean.java | 13 ++++++-- .../index/CandidateComponentsIndex.java | 30 ++++++++++--------- ...anningCandidateComponentProviderTests.java | 2 +- .../CandidateComponentsIndexLoaderTests.java | 4 +-- .../web/cors/DefaultCorsProcessor.java | 4 +-- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java index ef25a44202ee..62247b208a85 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/FactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2020 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. @@ -39,10 +39,16 @@ * *

{@code FactoryBean} is a programmatic contract. Implementations are not * supposed to rely on annotation-driven injection or other reflective facilities. - * {@link #getObjectType()} {@link #getObject()} invocations may arrive early in - * the bootstrap process, even ahead of any post-processor setup. If you need access + * {@link #getObjectType()} {@link #getObject()} invocations may arrive early in the + * bootstrap process, even ahead of any post-processor setup. If you need access to * other beans, implement {@link BeanFactoryAware} and obtain them programmatically. * + *

The container is only responsible for managing the lifecycle of the FactoryBean + * instance, not the lifecycle of the objects created by the FactoryBean. Therefore, + * a destroy method on an exposed bean object (such as {@link java.io.Closeable#close()} + * will not be called automatically. Instead, a FactoryBean should implement + * {@link DisposableBean} and delegate any such close call to the underlying object. + * *

Finally, FactoryBean objects participate in the containing BeanFactory's * synchronization of bean creation. There is usually no need for internal * synchronization other than for purposes of lazy initialization within the @@ -51,6 +57,7 @@ * @author Rod Johnson * @author Juergen Hoeller * @since 08.03.2003 + * @param the bean type * @see org.springframework.beans.factory.BeanFactory * @see org.springframework.aop.framework.ProxyFactoryBean * @see org.springframework.jndi.JndiObjectFactoryBean diff --git a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java index 40a96e5b2512..5d9c0becb112 100644 --- a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java +++ b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndex.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2020 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. @@ -57,6 +57,19 @@ public class CandidateComponentsIndex { this.index = parseIndex(content); } + private static MultiValueMap parseIndex(List content) { + MultiValueMap index = new LinkedMultiValueMap<>(); + for (Properties entry : content) { + entry.forEach((type, values) -> { + String[] stereotypes = ((String) values).split(","); + for (String stereotype : stereotypes) { + index.add(stereotype, new Entry((String) type)); + } + }); + } + return index; + } + /** * Return the candidate types that are associated with the specified stereotype. @@ -76,21 +89,11 @@ public Set getCandidateTypes(String basePackage, String stereotype) { return Collections.emptySet(); } - private static MultiValueMap parseIndex(List content) { - MultiValueMap index = new LinkedMultiValueMap<>(); - for (Properties entry : content) { - entry.forEach((type, values) -> { - String[] stereotypes = ((String) values).split(","); - for (String stereotype : stereotypes) { - index.add(stereotype, new Entry((String) type)); - } - }); - } - return index; - } private static class Entry { + private final String type; + private final String packageName; Entry(String type) { @@ -106,7 +109,6 @@ public boolean match(String basePackage) { return this.type.startsWith(basePackage); } } - } } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java index 1a7059eaebcf..b245a9b4bee7 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ClassPathScanningCandidateComponentProviderTests.java @@ -300,7 +300,7 @@ public void testWithComponentAnnotationOnly() { } @Test - public void testWithAspectAnnotationOnly() throws Exception { + public void testWithAspectAnnotationOnly() { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false); provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class)); Set candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE); diff --git a/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java b/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java index 97a53abb8d47..322bf1652606 100644 --- a/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java +++ b/spring-context/src/test/java/org/springframework/context/index/CandidateComponentsIndexLoaderTests.java @@ -92,7 +92,7 @@ public void loadIndexNoSpringComponentsResource() { } @Test - public void loadIndexNoEntry() throws IOException { + public void loadIndexNoEntry() { CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex( CandidateComponentsTestClassLoader.index(getClass().getClassLoader(), new ClassPathResource("empty-spring.components", getClass()))); @@ -100,7 +100,7 @@ public void loadIndexNoEntry() throws IOException { } @Test - public void loadIndexWithException() throws IOException { + public void loadIndexWithException() { final IOException cause = new IOException("test exception"); this.thrown.expect(IllegalStateException.class); this.thrown.expectMessage("Unable to load indexes"); diff --git a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java index 1c8b0ec136d7..4c336e945b80 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -186,7 +186,7 @@ protected String checkOrigin(CorsConfiguration config, @Nullable String requestO /** * Check the HTTP method and determine the methods for the response of a * pre-flight request. The default implementation simply delegates to - * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}. + * {@link org.springframework.web.cors.CorsConfiguration#checkHttpMethod(HttpMethod)}. */ @Nullable protected List checkMethods(CorsConfiguration config, @Nullable HttpMethod requestMethod) {