Skip to content

Commit e5207e6

Browse files
committed
Polishing
1 parent 1c10861 commit e5207e6

File tree

8 files changed

+69
-56
lines changed

8 files changed

+69
-56
lines changed

spring-aspects/src/main/java/org/springframework/context/annotation/aspectj/SpringConfiguredConfiguration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,9 +28,9 @@
2828
* annotated with @{@link org.springframework.beans.factory.annotation.Configurable
2929
* Configurable}.
3030
*
31-
* <p>This configuration class is automatically imported when using the @{@link
32-
* EnableSpringConfigured} annotation. See {@code @EnableSpringConfigured} Javadoc for
33-
* complete usage details.
31+
* <p>This configuration class is automatically imported when using the
32+
* @{@link EnableSpringConfigured} annotation. See {@code @EnableSpringConfigured}'s
33+
* javadoc for complete usage details.
3434
*
3535
* @author Chris Beams
3636
* @since 3.1
@@ -42,9 +42,10 @@ public class SpringConfiguredConfiguration {
4242
public static final String BEAN_CONFIGURER_ASPECT_BEAN_NAME =
4343
"org.springframework.context.config.internalBeanConfigurerAspect";
4444

45-
@Bean(name=BEAN_CONFIGURER_ASPECT_BEAN_NAME)
45+
@Bean(name = BEAN_CONFIGURER_ASPECT_BEAN_NAME)
4646
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
4747
public AnnotationBeanConfigurerAspect beanConfigurerAspect() {
4848
return AnnotationBeanConfigurerAspect.aspectOf();
4949
}
50+
5051
}

spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package org.springframework.cache.annotation;
1818

1919
import java.util.Collection;
20-
2120
import javax.annotation.PostConstruct;
2221

2322
import org.springframework.beans.factory.annotation.Autowired;
@@ -27,12 +26,11 @@
2726
import org.springframework.context.annotation.ImportAware;
2827
import org.springframework.core.annotation.AnnotationAttributes;
2928
import org.springframework.core.type.AnnotationMetadata;
30-
import org.springframework.util.Assert;
3129
import org.springframework.util.CollectionUtils;
3230

3331
/**
34-
* Abstract base {@code @Configuration} class providing common structure for enabling
35-
* Spring's annotation-driven cache management capability.
32+
* Abstract base {@code @Configuration} class providing common structure
33+
* for enabling Spring's annotation-driven cache management capability.
3634
*
3735
* @author Chris Beams
3836
* @since 3.1
@@ -42,22 +40,28 @@
4240
public abstract class AbstractCachingConfiguration implements ImportAware {
4341

4442
protected AnnotationAttributes enableCaching;
43+
4544
protected CacheManager cacheManager;
45+
4646
protected KeyGenerator keyGenerator;
4747

48-
@Autowired(required=false)
48+
@Autowired(required = false)
4949
private Collection<CacheManager> cacheManagerBeans;
50-
@Autowired(required=false)
50+
51+
@Autowired(required = false)
5152
private Collection<CachingConfigurer> cachingConfigurers;
5253

54+
5355
public void setImportMetadata(AnnotationMetadata importMetadata) {
5456
this.enableCaching = AnnotationAttributes.fromMap(
5557
importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
56-
Assert.notNull(this.enableCaching,
57-
"@EnableCaching is not present on importing class " +
58-
importMetadata.getClassName());
58+
if (this.enableCaching == null) {
59+
throw new IllegalArgumentException(
60+
"@EnableCaching is not present on importing class " + importMetadata.getClassName());
61+
}
5962
}
6063

64+
6165
/**
6266
* Determine which {@code CacheManager} bean to use. Prefer the result of
6367
* {@link CachingConfigurer#cacheManager()} over any by-type matching. If none, fall
@@ -68,29 +72,28 @@ public void setImportMetadata(AnnotationMetadata importMetadata) {
6872
*/
6973
@PostConstruct
7074
protected void reconcileCacheManager() {
71-
if (!CollectionUtils.isEmpty(cachingConfigurers)) {
72-
int nConfigurers = cachingConfigurers.size();
75+
if (!CollectionUtils.isEmpty(this.cachingConfigurers)) {
76+
int nConfigurers = this.cachingConfigurers.size();
7377
if (nConfigurers > 1) {
7478
throw new IllegalStateException(nConfigurers + " implementations of " +
7579
"CachingConfigurer were found when only 1 was expected. " +
7680
"Refactor the configuration such that CachingConfigurer is " +
7781
"implemented only once or not at all.");
7882
}
79-
CachingConfigurer cachingConfigurer = cachingConfigurers.iterator().next();
83+
CachingConfigurer cachingConfigurer = this.cachingConfigurers.iterator().next();
8084
this.cacheManager = cachingConfigurer.cacheManager();
8185
this.keyGenerator = cachingConfigurer.keyGenerator();
8286
}
83-
else if (!CollectionUtils.isEmpty(cacheManagerBeans)) {
84-
int nManagers = cacheManagerBeans.size();
87+
else if (!CollectionUtils.isEmpty(this.cacheManagerBeans)) {
88+
int nManagers = this.cacheManagerBeans.size();
8589
if (nManagers > 1) {
8690
throw new IllegalStateException(nManagers + " beans of type CacheManager " +
8791
"were found when only 1 was expected. Remove all but one of the " +
8892
"CacheManager bean definitions, or implement CachingConfigurer " +
8993
"to make explicit which CacheManager should be used for " +
9094
"annotation-driven cache management.");
9195
}
92-
CacheManager cacheManager = cacheManagerBeans.iterator().next();
93-
this.cacheManager = cacheManager;
96+
this.cacheManager = cacheManager = this.cacheManagerBeans.iterator().next();
9497
// keyGenerator remains null; will fall back to default within CacheInterceptor
9598
}
9699
else {
@@ -99,4 +102,5 @@ else if (!CollectionUtils.isEmpty(cacheManagerBeans)) {
99102
"from your configuration.");
100103
}
101104
}
105+
102106
}

spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,16 +26,15 @@
2626
import org.springframework.core.annotation.AnnotationAttributes;
2727
import org.springframework.core.type.AnnotationMetadata;
2828
import org.springframework.instrument.classloading.LoadTimeWeaver;
29-
import org.springframework.util.Assert;
3029

3130
import static org.springframework.context.weaving.AspectJWeavingEnabler.*;
3231

3332
/**
3433
* {@code @Configuration} class that registers a {@link LoadTimeWeaver} bean.
3534
*
36-
* <p>This configuration class is automatically imported when using the @{@link
37-
* EnableLoadTimeWeaving} annotation. See {@code @EnableLoadTimeWeaving} Javadoc for
38-
* complete usage details.
35+
* <p>This configuration class is automatically imported when using the
36+
* {@link EnableLoadTimeWeaving} annotation. See {@code @EnableLoadTimeWeaving}
37+
* javadoc for complete usage details.
3938
*
4039
* @author Chris Beams
4140
* @since 3.1
@@ -47,28 +46,31 @@ public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoade
4746

4847
private AnnotationAttributes enableLTW;
4948

50-
@Autowired(required=false)
49+
@Autowired(required = false)
5150
private LoadTimeWeavingConfigurer ltwConfigurer;
5251

5352
private ClassLoader beanClassLoader;
5453

54+
5555
public void setImportMetadata(AnnotationMetadata importMetadata) {
5656
this.enableLTW = MetadataUtils.attributesFor(importMetadata, EnableLoadTimeWeaving.class);
57-
Assert.notNull(this.enableLTW,
58-
"@EnableLoadTimeWeaving is not present on importing class " +
59-
importMetadata.getClassName());
57+
if (this.enableLTW == null) {
58+
throw new IllegalArgumentException(
59+
"@EnableLoadTimeWeaving is not present on importing class " + importMetadata.getClassName());
60+
}
6061
}
6162

6263
public void setBeanClassLoader(ClassLoader beanClassLoader) {
6364
this.beanClassLoader = beanClassLoader;
6465
}
6566

66-
@Bean(name=ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME)
67+
68+
@Bean(name = ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME)
6769
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
6870
public LoadTimeWeaver loadTimeWeaver() {
6971
LoadTimeWeaver loadTimeWeaver = null;
7072

71-
if (ltwConfigurer != null) {
73+
if (this.ltwConfigurer != null) {
7274
// the user has provided a custom LTW instance
7375
loadTimeWeaver = ltwConfigurer.getLoadTimeWeaver();
7476
}

spring-context/src/main/java/org/springframework/context/annotation/MBeanExportConfiguration.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@
3030
import org.springframework.jmx.support.RegistrationPolicy;
3131
import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean;
3232
import org.springframework.jndi.JndiLocatorDelegate;
33-
import org.springframework.util.Assert;
3433
import org.springframework.util.ClassUtils;
3534
import org.springframework.util.StringUtils;
3635

@@ -50,23 +49,26 @@ public class MBeanExportConfiguration implements ImportAware, BeanFactoryAware {
5049

5150
private static final String MBEAN_EXPORTER_BEAN_NAME = "mbeanExporter";
5251

53-
private AnnotationAttributes attributes;
52+
private AnnotationAttributes enableMBeanExport;
5453

5554
private BeanFactory beanFactory;
5655

5756

5857
public void setImportMetadata(AnnotationMetadata importMetadata) {
5958
Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableMBeanExport.class.getName());
60-
this.attributes = AnnotationAttributes.fromMap(map);
61-
Assert.notNull(this.attributes,
62-
"@EnableMBeanExport is not present on importing class " + importMetadata.getClassName());
59+
this.enableMBeanExport = AnnotationAttributes.fromMap(map);
60+
if (this.enableMBeanExport == null) {
61+
throw new IllegalArgumentException(
62+
"@EnableMBeanExport is not present on importing class " + importMetadata.getClassName());
63+
}
6364
}
6465

6566
public void setBeanFactory(BeanFactory beanFactory) {
6667
this.beanFactory = beanFactory;
6768
}
6869

69-
@Bean(name=MBEAN_EXPORTER_BEAN_NAME)
70+
71+
@Bean(name = MBEAN_EXPORTER_BEAN_NAME)
7072
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
7173
public AnnotationMBeanExporter mbeanExporter() {
7274
AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
@@ -77,14 +79,14 @@ public AnnotationMBeanExporter mbeanExporter() {
7779
}
7880

7981
private void setupDomain(AnnotationMBeanExporter exporter) {
80-
String defaultDomain = this.attributes.getString("defaultDomain");
82+
String defaultDomain = this.enableMBeanExport.getString("defaultDomain");
8183
if (StringUtils.hasText(defaultDomain)) {
8284
exporter.setDefaultDomain(defaultDomain);
8385
}
8486
}
8587

8688
private void setupServer(AnnotationMBeanExporter exporter) {
87-
String server = this.attributes.getString("server");
89+
String server = this.enableMBeanExport.getString("server");
8890
if (StringUtils.hasText(server)) {
8991
exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class));
9092
}
@@ -97,7 +99,7 @@ private void setupServer(AnnotationMBeanExporter exporter) {
9799
}
98100

99101
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
100-
RegistrationPolicy registrationPolicy = this.attributes.getEnum("registration");
102+
RegistrationPolicy registrationPolicy = this.enableMBeanExport.getEnum("registration");
101103
exporter.setRegistrationPolicy(registrationPolicy);
102104
}
103105

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424
import org.springframework.context.annotation.ImportAware;
2525
import org.springframework.core.annotation.AnnotationAttributes;
2626
import org.springframework.core.type.AnnotationMetadata;
27-
import org.springframework.util.Assert;
2827
import org.springframework.util.CollectionUtils;
2928

3029
/**
@@ -46,14 +45,16 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
4645
public void setImportMetadata(AnnotationMetadata importMetadata) {
4746
this.enableAsync = AnnotationAttributes.fromMap(
4847
importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
49-
Assert.notNull(this.enableAsync,
50-
"@EnableAsync is not present on importing class " + importMetadata.getClassName());
48+
if (this.enableAsync == null) {
49+
throw new IllegalArgumentException(
50+
"@EnableAsync is not present on importing class " + importMetadata.getClassName());
51+
}
5152
}
5253

5354
/**
5455
* Collect any {@link AsyncConfigurer} beans through autowiring.
5556
*/
56-
@Autowired(required=false)
57+
@Autowired(required = false)
5758
void setConfigurers(Collection<AsyncConfigurer> configurers) {
5859
if (CollectionUtils.isEmpty(configurers)) {
5960
return;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.springframework.core.annotation.AnnotationAttributes;
2525
import org.springframework.core.type.AnnotationMetadata;
2626
import org.springframework.transaction.PlatformTransactionManager;
27-
import org.springframework.util.Assert;
2827
import org.springframework.util.CollectionUtils;
2928

3029
/**
@@ -49,8 +48,10 @@ public abstract class AbstractTransactionManagementConfiguration implements Impo
4948
public void setImportMetadata(AnnotationMetadata importMetadata) {
5049
this.enableTx = AnnotationAttributes.fromMap(
5150
importMetadata.getAnnotationAttributes(EnableTransactionManagement.class.getName(), false));
52-
Assert.notNull(this.enableTx,
53-
"@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName());
51+
if (this.enableTx == null) {
52+
throw new IllegalArgumentException(
53+
"@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName());
54+
}
5455
}
5556

5657
@Autowired(required = false)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@
2626
import org.springframework.transaction.interceptor.TransactionInterceptor;
2727

2828
/**
29-
* {@code @Configuration} class that registers the Spring infrastructure beans necessary
30-
* to enable proxy-based annotation-driven transaction management.
29+
* {@code @Configuration} class that registers the Spring infrastructure beans
30+
* necessary to enable proxy-based annotation-driven transaction management.
3131
*
3232
* @author Chris Beams
3333
* @since 3.1
@@ -37,7 +37,7 @@
3737
@Configuration
3838
public class ProxyTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration {
3939

40-
@Bean(name=TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME)
40+
@Bean(name = TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME)
4141
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
4242
public BeanFactoryTransactionAttributeSourceAdvisor transactionAdvisor() {
4343
BeanFactoryTransactionAttributeSourceAdvisor advisor = new BeanFactoryTransactionAttributeSourceAdvisor();

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
4242

4343
private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite();
4444

45+
4546
@Autowired(required = false)
4647
public void setConfigurers(List<WebMvcConfigurer> configurers) {
4748
if (configurers == null || configurers.isEmpty()) {
@@ -50,6 +51,7 @@ public void setConfigurers(List<WebMvcConfigurer> configurers) {
5051
this.configurers.addWebMvcConfigurers(configurers);
5152
}
5253

54+
5355
@Override
5456
protected void addInterceptors(InterceptorRegistry registry) {
5557
this.configurers.addInterceptors(registry);

0 commit comments

Comments
 (0)