Browse Source

Polishing

(cherry picked from commit 7c9ba80f85)
pull/1916/head
Juergen Hoeller 8 years ago
parent
commit
b6a049a088
  1. 16
      spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java
  2. 15
      spring-context/src/main/java/org/springframework/context/annotation/AdviceModeImportSelector.java
  3. 7
      spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java
  4. 40
      spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java
  5. 19
      spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java
  6. 16
      spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurationSelector.java

16
spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurationSelector.java vendored

@ -26,9 +26,9 @@ import org.springframework.util.ClassUtils; @@ -26,9 +26,9 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
/**
* Selects which implementation of {@link AbstractCachingConfiguration} should be used
* based on the value of {@link EnableCaching#mode} on the importing {@code @Configuration}
* class.
* Selects which implementation of {@link AbstractCachingConfiguration} should
* be used based on the value of {@link EnableCaching#mode} on the importing
* {@code @Configuration} class.
*
* <p>Detects the presence of JSR-107 and enables JCache support accordingly.
*
@ -58,9 +58,9 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl @@ -58,9 +58,9 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
/**
* {@inheritDoc}
* @return {@link ProxyCachingConfiguration} or {@code AspectJCacheConfiguration} for
* {@code PROXY} and {@code ASPECTJ} values of {@link EnableCaching#mode()}, respectively
* Returns {@link ProxyCachingConfiguration} or {@code AspectJCachingConfiguration}
* for {@code PROXY} and {@code ASPECTJ} values of {@link EnableCaching#mode()},
* respectively. Potentially includes corresponding JCache configuration as well.
*/
@Override
public String[] selectImports(AdviceMode adviceMode) {
@ -79,7 +79,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl @@ -79,7 +79,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
* <p>Take care of adding the necessary JSR-107 import if it is available.
*/
private String[] getProxyImports() {
List<String> result = new ArrayList<>();
List<String> result = new ArrayList<>(3);
result.add(AutoProxyRegistrar.class.getName());
result.add(ProxyCachingConfiguration.class.getName());
if (jsr107Present && jcacheImplPresent) {
@ -93,7 +93,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl @@ -93,7 +93,7 @@ public class CachingConfigurationSelector extends AdviceModeImportSelector<Enabl
* <p>Take care of adding the necessary JSR-107 import if it is available.
*/
private String[] getAspectJImports() {
List<String> result = new ArrayList<>();
List<String> result = new ArrayList<>(2);
result.add(CACHE_ASPECT_CONFIGURATION_CLASS_NAME);
if (jsr107Present && jcacheImplPresent) {
result.add(JCACHE_ASPECT_CONFIGURATION_CLASS_NAME);

15
spring-context/src/main/java/org/springframework/context/annotation/AdviceModeImportSelector.java

@ -1,5 +1,5 @@ @@ -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.
@ -35,6 +35,9 @@ import org.springframework.util.Assert; @@ -35,6 +35,9 @@ import org.springframework.util.Assert;
*/
public abstract class AdviceModeImportSelector<A extends Annotation> implements ImportSelector {
/**
* The default advice mode attribute name.
*/
public static final String DEFAULT_ADVICE_MODE_ATTRIBUTE_NAME = "mode";
@ -81,13 +84,13 @@ public abstract class AdviceModeImportSelector<A extends Annotation> implements @@ -81,13 +84,13 @@ public abstract class AdviceModeImportSelector<A extends Annotation> implements
/**
* Determine which classes should be imported based on the given {@code AdviceMode}.
* <p>Returning {@code null} from this method indicates that the {@code AdviceMode} could
* not be handled or was unknown and that an {@code IllegalArgumentException} should
* be thrown.
* <p>Returning {@code null} from this method indicates that the {@code AdviceMode}
* could not be handled or was unknown and that an {@code IllegalArgumentException}
* should be thrown.
* @param adviceMode the value of the {@linkplain #getAdviceModeAttributeName()
* advice mode attribute} for the annotation specified via generics.
* @return array containing classes to import; empty array if none, {@code null} if
* the given {@code AdviceMode} is unknown.
* @return array containing classes to import (empty array if none;
* {@code null} if the given {@code AdviceMode} is unknown)
*/
@Nullable
protected abstract String[] selectImports(AdviceMode adviceMode);

7
spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigApplicationContext.java

@ -1,5 +1,5 @@ @@ -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.
@ -101,9 +101,8 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex @@ -101,9 +101,8 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
/**
* {@inheritDoc}
* <p>Delegates given environment to underlying {@link AnnotatedBeanDefinitionReader}
* and {@link ClassPathBeanDefinitionScanner} members.
* Propagates the given custom {@code Environment} to the underlying
* {@link AnnotatedBeanDefinitionReader} and {@link ClassPathBeanDefinitionScanner}.
*/
@Override
public void setEnvironment(ConfigurableEnvironment environment) {

40
spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java

@ -41,10 +41,10 @@ import org.springframework.util.StringValueResolver; @@ -41,10 +41,10 @@ import org.springframework.util.StringValueResolver;
* Spring {@link Environment} and its set of {@link PropertySources}.
*
* <p>This class is designed as a general replacement for {@code PropertyPlaceholderConfigurer}
* in Spring 3.1 applications. It is used by default to support the {@code property-placeholder}
* element in working against the spring-context-3.1 XSD, whereas spring-context versions
* &lt;= 3.0 default to {@code PropertyPlaceholderConfigurer} to ensure backward compatibility.
* See the spring-context XSD documentation for complete details.
* introduced in Spring 3.1. It is used by default to support the {@code property-placeholder}
* element in working against the spring-context-3.1 or higher XSD, whereas spring-context
* versions &lt;= 3.0 default to {@code PropertyPlaceholderConfigurer} to ensure backward
* compatibility. See the spring-context XSD documentation for complete details.
*
* <p>Any local properties (e.g. those added via {@link #setProperties}, {@link #setLocations}
* et al.) are added as a {@code PropertySource}. Search precedence of local properties is
@ -52,10 +52,11 @@ import org.springframework.util.StringValueResolver; @@ -52,10 +52,11 @@ import org.springframework.util.StringValueResolver;
* default {@code false} meaning that local properties are to be searched last, after all
* environment property sources.
*
* <p>See {@link org.springframework.core.env.ConfigurableEnvironment ConfigurableEnvironment}
* and related javadocs for details on manipulating environment property sources.
* <p>See {@link org.springframework.core.env.ConfigurableEnvironment} and related javadocs
* for details on manipulating environment property sources.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
* @see org.springframework.core.env.ConfigurableEnvironment
* @see org.springframework.beans.factory.config.PlaceholderConfigurerSupport
@ -88,8 +89,8 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS @@ -88,8 +89,8 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS
/**
* Customize the set of {@link PropertySources} to be used by this configurer.
* Setting this property indicates that environment property sources and local
* properties should be ignored.
* <p>Setting this property indicates that environment property sources and
* local properties should be ignored.
* @see #postProcessBeanFactory
*/
public void setPropertySources(PropertySources propertySources) {
@ -97,8 +98,8 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS @@ -97,8 +98,8 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS
}
/**
* {@inheritDoc}
* <p>{@code PropertySources} from this environment will be searched when replacing ${...} placeholders.
* {@code PropertySources} from the given {@link Environment}
* will be searched when replacing ${...} placeholders.
* @see #setPropertySources
* @see #postProcessBeanFactory
*/
@ -109,8 +110,7 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS @@ -109,8 +110,7 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS
/**
* {@inheritDoc}
* <p>Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
* Processing occurs by replacing ${...} placeholders in bean definitions by resolving each
* against this configurer's set of {@link PropertySources}, which includes:
* <ul>
* <li>all {@linkplain org.springframework.core.env.ConfigurableEnvironment#getPropertySources
@ -170,21 +170,23 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS @@ -170,21 +170,23 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS
propertyResolver.setValueSeparator(this.valueSeparator);
StringValueResolver valueResolver = strVal -> {
String resolved = (ignoreUnresolvablePlaceholders ?
String resolved = (this.ignoreUnresolvablePlaceholders ?
propertyResolver.resolvePlaceholders(strVal) :
propertyResolver.resolveRequiredPlaceholders(strVal));
if (trimValues) {
if (this.trimValues) {
resolved = resolved.trim();
}
return (resolved.equals(nullValue) ? null : resolved);
return (resolved.equals(this.nullValue) ? null : resolved);
};
doProcessProperties(beanFactoryToProcess, valueResolver);
}
/**
* Implemented for compatibility with {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}.
* @deprecated in favor of {@link #processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)}
* Implemented for compatibility with
* {@link org.springframework.beans.factory.config.PlaceholderConfigurerSupport}.
* @deprecated in favor of
* {@link #processProperties(ConfigurableListableBeanFactory, ConfigurablePropertyResolver)}
* @throws UnsupportedOperationException in this implementation
*/
@Override
@ -195,14 +197,14 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS @@ -195,14 +197,14 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS
}
/**
* Returns the property sources that were actually applied during
* Return the property sources that were actually applied during
* {@link #postProcessBeanFactory(ConfigurableListableBeanFactory) post-processing}.
* @return the property sources that were applied
* @throws IllegalStateException if the property sources have not yet been applied
* @since 4.0
*/
public PropertySources getAppliedPropertySources() throws IllegalStateException {
Assert.state(this.appliedPropertySources != null, "PropertySources have not get been applied");
Assert.state(this.appliedPropertySources != null, "PropertySources have not yet been applied");
return this.appliedPropertySources;
}

19
spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 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.
@ -21,10 +21,12 @@ import org.springframework.context.annotation.AdviceModeImportSelector; @@ -21,10 +21,12 @@ import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.lang.Nullable;
/**
* Selects which implementation of {@link AbstractAsyncConfiguration} should be used based
* on the value of {@link EnableAsync#mode} on the importing {@code @Configuration} class.
* Selects which implementation of {@link AbstractAsyncConfiguration} should
* be used based on the value of {@link EnableAsync#mode} on the importing
* {@code @Configuration} class.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
* @see EnableAsync
* @see ProxyAsyncConfiguration
@ -34,19 +36,20 @@ public class AsyncConfigurationSelector extends AdviceModeImportSelector<EnableA @@ -34,19 +36,20 @@ public class AsyncConfigurationSelector extends AdviceModeImportSelector<EnableA
private static final String ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME =
"org.springframework.scheduling.aspectj.AspectJAsyncConfiguration";
/**
* {@inheritDoc}
* @return {@link ProxyAsyncConfiguration} or {@code AspectJAsyncConfiguration} for
* {@code PROXY} and {@code ASPECTJ} values of {@link EnableAsync#mode()}, respectively
* Returns {@link ProxyAsyncConfiguration} or {@code AspectJAsyncConfiguration}
* for {@code PROXY} and {@code ASPECTJ} values of {@link EnableAsync#mode()},
* respectively.
*/
@Override
@Nullable
public String[] selectImports(AdviceMode adviceMode) {
switch (adviceMode) {
case PROXY:
return new String[] { ProxyAsyncConfiguration.class.getName() };
return new String[] {ProxyAsyncConfiguration.class.getName()};
case ASPECTJ:
return new String[] { ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME };
return new String[] {ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME};
default:
return null;
}

16
spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurationSelector.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 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.
@ -35,18 +35,20 @@ import org.springframework.transaction.config.TransactionManagementConfigUtils; @@ -35,18 +35,20 @@ import org.springframework.transaction.config.TransactionManagementConfigUtils;
public class TransactionManagementConfigurationSelector extends AdviceModeImportSelector<EnableTransactionManagement> {
/**
* {@inheritDoc}
* @return {@link ProxyTransactionManagementConfiguration} or
* {@code AspectJTransactionManagementConfiguration} for {@code PROXY} and
* {@code ASPECTJ} values of {@link EnableTransactionManagement#mode()}, respectively
* Returns {@link ProxyTransactionManagementConfiguration} or
* {@code AspectJTransactionManagementConfiguration} for {@code PROXY}
* and {@code ASPECTJ} values of {@link EnableTransactionManagement#mode()},
* respectively.
*/
@Override
protected String[] selectImports(AdviceMode adviceMode) {
switch (adviceMode) {
case PROXY:
return new String[] {AutoProxyRegistrar.class.getName(), ProxyTransactionManagementConfiguration.class.getName()};
return new String[] {AutoProxyRegistrar.class.getName(),
ProxyTransactionManagementConfiguration.class.getName()};
case ASPECTJ:
return new String[] {TransactionManagementConfigUtils.TRANSACTION_ASPECT_CONFIGURATION_CLASS_NAME};
return new String[] {
TransactionManagementConfigUtils.TRANSACTION_ASPECT_CONFIGURATION_CLASS_NAME};
default:
return null;
}

Loading…
Cancel
Save