Polishing
This commit is contained in:
parent
1c10861a92
commit
e5207e6231
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -28,9 +28,9 @@ import org.springframework.context.annotation.Role;
|
|||
* annotated with @{@link org.springframework.beans.factory.annotation.Configurable
|
||||
* Configurable}.
|
||||
*
|
||||
* <p>This configuration class is automatically imported when using the @{@link
|
||||
* EnableSpringConfigured} annotation. See {@code @EnableSpringConfigured} Javadoc for
|
||||
* complete usage details.
|
||||
* <p>This configuration class is automatically imported when using the
|
||||
* @{@link EnableSpringConfigured} annotation. See {@code @EnableSpringConfigured}'s
|
||||
* javadoc for complete usage details.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
|
@ -47,4 +47,5 @@ public class SpringConfiguredConfiguration {
|
|||
public AnnotationBeanConfigurerAspect beanConfigurerAspect() {
|
||||
return AnnotationBeanConfigurerAspect.aspectOf();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.cache.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -27,12 +26,11 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.context.annotation.ImportAware;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* Abstract base {@code @Configuration} class providing common structure for enabling
|
||||
* Spring's annotation-driven cache management capability.
|
||||
* Abstract base {@code @Configuration} class providing common structure
|
||||
* for enabling Spring's annotation-driven cache management capability.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
|
@ -42,21 +40,27 @@ import org.springframework.util.CollectionUtils;
|
|||
public abstract class AbstractCachingConfiguration implements ImportAware {
|
||||
|
||||
protected AnnotationAttributes enableCaching;
|
||||
|
||||
protected CacheManager cacheManager;
|
||||
|
||||
protected KeyGenerator keyGenerator;
|
||||
|
||||
@Autowired(required = false)
|
||||
private Collection<CacheManager> cacheManagerBeans;
|
||||
|
||||
@Autowired(required = false)
|
||||
private Collection<CachingConfigurer> cachingConfigurers;
|
||||
|
||||
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableCaching = AnnotationAttributes.fromMap(
|
||||
importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
|
||||
Assert.notNull(this.enableCaching,
|
||||
"@EnableCaching is not present on importing class " +
|
||||
importMetadata.getClassName());
|
||||
if (this.enableCaching == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"@EnableCaching is not present on importing class " + importMetadata.getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine which {@code CacheManager} bean to use. Prefer the result of
|
||||
|
@ -68,20 +72,20 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
|
|||
*/
|
||||
@PostConstruct
|
||||
protected void reconcileCacheManager() {
|
||||
if (!CollectionUtils.isEmpty(cachingConfigurers)) {
|
||||
int nConfigurers = cachingConfigurers.size();
|
||||
if (!CollectionUtils.isEmpty(this.cachingConfigurers)) {
|
||||
int nConfigurers = this.cachingConfigurers.size();
|
||||
if (nConfigurers > 1) {
|
||||
throw new IllegalStateException(nConfigurers + " implementations of " +
|
||||
"CachingConfigurer were found when only 1 was expected. " +
|
||||
"Refactor the configuration such that CachingConfigurer is " +
|
||||
"implemented only once or not at all.");
|
||||
}
|
||||
CachingConfigurer cachingConfigurer = cachingConfigurers.iterator().next();
|
||||
CachingConfigurer cachingConfigurer = this.cachingConfigurers.iterator().next();
|
||||
this.cacheManager = cachingConfigurer.cacheManager();
|
||||
this.keyGenerator = cachingConfigurer.keyGenerator();
|
||||
}
|
||||
else if (!CollectionUtils.isEmpty(cacheManagerBeans)) {
|
||||
int nManagers = cacheManagerBeans.size();
|
||||
else if (!CollectionUtils.isEmpty(this.cacheManagerBeans)) {
|
||||
int nManagers = this.cacheManagerBeans.size();
|
||||
if (nManagers > 1) {
|
||||
throw new IllegalStateException(nManagers + " beans of type CacheManager " +
|
||||
"were found when only 1 was expected. Remove all but one of the " +
|
||||
|
@ -89,8 +93,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
|
|||
"to make explicit which CacheManager should be used for " +
|
||||
"annotation-driven cache management.");
|
||||
}
|
||||
CacheManager cacheManager = cacheManagerBeans.iterator().next();
|
||||
this.cacheManager = cacheManager;
|
||||
this.cacheManager = cacheManager = this.cacheManagerBeans.iterator().next();
|
||||
// keyGenerator remains null; will fall back to default within CacheInterceptor
|
||||
}
|
||||
else {
|
||||
|
@ -99,4 +102,5 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
|
|||
"from your configuration.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -26,16 +26,15 @@ import org.springframework.context.weaving.DefaultContextLoadTimeWeaver;
|
|||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.instrument.classloading.LoadTimeWeaver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.springframework.context.weaving.AspectJWeavingEnabler.*;
|
||||
|
||||
/**
|
||||
* {@code @Configuration} class that registers a {@link LoadTimeWeaver} bean.
|
||||
*
|
||||
* <p>This configuration class is automatically imported when using the @{@link
|
||||
* EnableLoadTimeWeaving} annotation. See {@code @EnableLoadTimeWeaving} Javadoc for
|
||||
* complete usage details.
|
||||
* <p>This configuration class is automatically imported when using the
|
||||
* {@link EnableLoadTimeWeaving} annotation. See {@code @EnableLoadTimeWeaving}
|
||||
* javadoc for complete usage details.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
|
@ -52,23 +51,26 @@ public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoade
|
|||
|
||||
private ClassLoader beanClassLoader;
|
||||
|
||||
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableLTW = MetadataUtils.attributesFor(importMetadata, EnableLoadTimeWeaving.class);
|
||||
Assert.notNull(this.enableLTW,
|
||||
"@EnableLoadTimeWeaving is not present on importing class " +
|
||||
importMetadata.getClassName());
|
||||
if (this.enableLTW == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"@EnableLoadTimeWeaving is not present on importing class " + importMetadata.getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
public void setBeanClassLoader(ClassLoader beanClassLoader) {
|
||||
this.beanClassLoader = beanClassLoader;
|
||||
}
|
||||
|
||||
|
||||
@Bean(name = ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME)
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public LoadTimeWeaver loadTimeWeaver() {
|
||||
LoadTimeWeaver loadTimeWeaver = null;
|
||||
|
||||
if (ltwConfigurer != null) {
|
||||
if (this.ltwConfigurer != null) {
|
||||
// the user has provided a custom LTW instance
|
||||
loadTimeWeaver = ltwConfigurer.getLoadTimeWeaver();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -30,7 +30,6 @@ import org.springframework.jmx.export.annotation.AnnotationMBeanExporter;
|
|||
import org.springframework.jmx.support.RegistrationPolicy;
|
||||
import org.springframework.jmx.support.WebSphereMBeanServerFactoryBean;
|
||||
import org.springframework.jndi.JndiLocatorDelegate;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
|
@ -50,22 +49,25 @@ public class MBeanExportConfiguration implements ImportAware, BeanFactoryAware {
|
|||
|
||||
private static final String MBEAN_EXPORTER_BEAN_NAME = "mbeanExporter";
|
||||
|
||||
private AnnotationAttributes attributes;
|
||||
private AnnotationAttributes enableMBeanExport;
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableMBeanExport.class.getName());
|
||||
this.attributes = AnnotationAttributes.fromMap(map);
|
||||
Assert.notNull(this.attributes,
|
||||
this.enableMBeanExport = AnnotationAttributes.fromMap(map);
|
||||
if (this.enableMBeanExport == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"@EnableMBeanExport is not present on importing class " + importMetadata.getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
|
||||
@Bean(name = MBEAN_EXPORTER_BEAN_NAME)
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public AnnotationMBeanExporter mbeanExporter() {
|
||||
|
@ -77,14 +79,14 @@ public class MBeanExportConfiguration implements ImportAware, BeanFactoryAware {
|
|||
}
|
||||
|
||||
private void setupDomain(AnnotationMBeanExporter exporter) {
|
||||
String defaultDomain = this.attributes.getString("defaultDomain");
|
||||
String defaultDomain = this.enableMBeanExport.getString("defaultDomain");
|
||||
if (StringUtils.hasText(defaultDomain)) {
|
||||
exporter.setDefaultDomain(defaultDomain);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupServer(AnnotationMBeanExporter exporter) {
|
||||
String server = this.attributes.getString("server");
|
||||
String server = this.enableMBeanExport.getString("server");
|
||||
if (StringUtils.hasText(server)) {
|
||||
exporter.setServer(this.beanFactory.getBean(server, MBeanServer.class));
|
||||
}
|
||||
|
@ -97,7 +99,7 @@ public class MBeanExportConfiguration implements ImportAware, BeanFactoryAware {
|
|||
}
|
||||
|
||||
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter) {
|
||||
RegistrationPolicy registrationPolicy = this.attributes.getEnum("registration");
|
||||
RegistrationPolicy registrationPolicy = this.enableMBeanExport.getEnum("registration");
|
||||
exporter.setRegistrationPolicy(registrationPolicy);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -24,7 +24,6 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.context.annotation.ImportAware;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
|
@ -46,9 +45,11 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
|
|||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableAsync = AnnotationAttributes.fromMap(
|
||||
importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
|
||||
Assert.notNull(this.enableAsync,
|
||||
if (this.enableAsync == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"@EnableAsync is not present on importing class " + importMetadata.getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect any {@link AsyncConfigurer} beans through autowiring.
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.springframework.context.annotation.ImportAware;
|
|||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
|
@ -49,9 +48,11 @@ public abstract class AbstractTransactionManagementConfiguration implements Impo
|
|||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableTx = AnnotationAttributes.fromMap(
|
||||
importMetadata.getAnnotationAttributes(EnableTransactionManagement.class.getName(), false));
|
||||
Assert.notNull(this.enableTx,
|
||||
if (this.enableTx == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
void setConfigurers(Collection<TransactionManagementConfigurer> configurers) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -26,8 +26,8 @@ import org.springframework.transaction.interceptor.TransactionAttributeSource;
|
|||
import org.springframework.transaction.interceptor.TransactionInterceptor;
|
||||
|
||||
/**
|
||||
* {@code @Configuration} class that registers the Spring infrastructure beans necessary
|
||||
* to enable proxy-based annotation-driven transaction management.
|
||||
* {@code @Configuration} class that registers the Spring infrastructure beans
|
||||
* necessary to enable proxy-based annotation-driven transaction management.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
@ -42,6 +42,7 @@ public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
|
||||
private final WebMvcConfigurerComposite configurers = new WebMvcConfigurerComposite();
|
||||
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setConfigurers(List<WebMvcConfigurer> configurers) {
|
||||
if (configurers == null || configurers.isEmpty()) {
|
||||
|
@ -50,6 +51,7 @@ public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
this.configurers.addWebMvcConfigurers(configurers);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void addInterceptors(InterceptorRegistry registry) {
|
||||
this.configurers.addInterceptors(registry);
|
||||
|
|
Loading…
Reference in New Issue