diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java index ab4fe292aa5..55d091394cb 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2006 the original author or authors. + * Copyright 2002-2014 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. @@ -25,7 +25,7 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; * TargetSourceCreator that enforces a LazyInitTargetSource for each bean * that is defined as "lazy-init". This will lead to a proxy created for * each of those beans, allowing to fetch a reference to such a bean - * without actually initialized the target bean instance. + * without actually initializing the target bean instance. * *

To be registered as custom TargetSourceCreator for an auto-proxy creator, * in combination with custom interceptors for specific beans or for the diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java index 1d917b6a1ba..b21cc4ba1a0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 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.apache.commons.logging.LogFactory; import org.springframework.aop.TargetSource; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; /** @@ -48,8 +47,7 @@ import org.springframework.util.ObjectUtils; * @see ThreadLocalTargetSource * @see CommonsPoolTargetSource */ -public abstract class AbstractBeanFactoryBasedTargetSource - implements TargetSource, BeanFactoryAware, Serializable { +public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSource, BeanFactoryAware, Serializable { /** use serialVersionUID from Spring 1.2.7 for interoperability */ private static final long serialVersionUID = -4721607536018568393L; @@ -108,7 +106,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource @Override public void setBeanFactory(BeanFactory beanFactory) { if (this.targetBeanName == null) { - throw new IllegalStateException("Property'targetBeanName' is required"); + throw new IllegalStateException("Property 'targetBeanName' is required"); } this.beanFactory = beanFactory; } @@ -185,8 +183,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(ClassUtils.getShortName(getClass())); + StringBuilder sb = new StringBuilder(getClass().getSimpleName()); sb.append(" for target bean '").append(this.targetBeanName).append("'"); if (this.targetClass != null) { sb.append(" of type [").append(this.targetClass.getName()).append("]"); diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomisationTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java similarity index 95% rename from spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomisationTests.java rename to spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java index 1a2bd2d27f8..3c81052b927 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomisationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java @@ -16,9 +16,6 @@ package org.springframework.cache.interceptor; -import static org.junit.Assert.*; -import static org.springframework.cache.CacheTestUtils.*; - import java.lang.reflect.Method; import java.util.Collection; import java.util.Collections; @@ -26,6 +23,7 @@ import java.util.concurrent.atomic.AtomicLong; import org.junit.Before; import org.junit.Test; + import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; @@ -40,12 +38,16 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.ReflectionUtils; +import static org.junit.Assert.*; +import static org.springframework.cache.CacheTestUtils.*; + /** * Provides various {@link CacheResolver} customisations scenario * * @author Stephane Nicoll + * @since 4.1 */ -public class CacheResolverCustomisationTests { +public class CacheResolverCustomizationTests { private CacheManager cacheManager; @@ -127,13 +129,13 @@ public class CacheResolverCustomisationTests { @Test public void noCacheResolved() { - Method m = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class); + Method method = ReflectionUtils.findMethod(SimpleService.class, "noCacheResolved", Object.class); try { simpleService.noCacheResolved(new Object()); fail("Should have failed, no cache resolved"); - } catch (IllegalStateException e) { - String msg = e.getMessage(); - assertTrue("Reference to the method must be contained in the message", msg.contains(m.toString())); + } + catch (IllegalStateException ex) { + assertTrue("Reference to the method must be contained in the message", ex.getMessage().contains(method.toString())); } } @@ -142,13 +144,13 @@ public class CacheResolverCustomisationTests { try { simpleService.unknownCacheResolver(new Object()); fail("Should have failed, no cache resolver with that name"); - } catch (NoSuchBeanDefinitionException e) { - assertEquals("Wrong bean name in exception", "unknownCacheResolver", e.getBeanName()); + } + catch (NoSuchBeanDefinitionException ex) { + assertEquals("Wrong bean name in exception", "unknownCacheResolver", ex.getBeanName()); } } - @Configuration @EnableCaching static class Config extends CachingConfigurerSupport { @@ -204,6 +206,7 @@ public class CacheResolverCustomisationTests { } } + @CacheConfig(cacheNames = "default") static class SimpleService { @@ -245,6 +248,7 @@ public class CacheResolverCustomisationTests { } } + /** * Example of {@link CacheResolver} that resolve the caches at * runtime (i.e. based on method invocation parameters). @@ -263,6 +267,7 @@ public class CacheResolverCustomisationTests { } } + private static class NullCacheResolver extends AbstractCacheResolver { private NullCacheResolver(CacheManager cacheManager) { diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostConstructAndAutowiringTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostConstructAndAutowiringTests.java index 6972adada9a..732d080fe1f 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostConstructAndAutowiringTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostConstructAndAutowiringTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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,6 +101,7 @@ public class ConfigurationClassPostConstructAndAutowiringTests { @Configuration static class Config2 { + TestBean testBean; @Autowired diff --git a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java index ac2529c1d11..0cc67323811 100644 --- a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java @@ -258,11 +258,10 @@ public class JmsListenerAnnotationBeanPostProcessor /** * Resolve the specified value if possible. - * * @see ConfigurableBeanFactory#resolveEmbeddedValue */ private String resolve(String value) { - if (this.beanFactory != null && this.beanFactory instanceof ConfigurableBeanFactory) { + if (this.beanFactory instanceof ConfigurableBeanFactory) { return ((ConfigurableBeanFactory) this.beanFactory).resolveEmbeddedValue(value); } return value; diff --git a/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java b/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java index c1649d86f15..b8b848dbb1e 100644 --- a/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java +++ b/src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java @@ -87,26 +87,11 @@ import static org.springframework.core.env.EnvironmentIntegrationTests.Constants public class EnvironmentIntegrationTests { private ConfigurableEnvironment prodEnv; + private ConfigurableEnvironment devEnv; + private ConfigurableEnvironment prodWebEnv; - /** - * Constants used both locally and in scan* sub-packages - */ - public static class Constants { - public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml"; - - public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean"; - - public static final String PROD_BEAN_NAME = "prodBean"; - public static final String DEV_BEAN_NAME = "devBean"; - public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean"; - public static final String TRANSITIVE_BEAN_NAME = "transitiveBean"; - - public static final String PROD_ENV_NAME = "prod"; - public static final String DEV_ENV_NAME = "dev"; - public static final String DERIVED_DEV_ENV_NAME = "derivedDev"; - } @Before public void setUp() { @@ -122,9 +107,7 @@ public class EnvironmentIntegrationTests { @Test public void genericApplicationContext_standardEnv() { - ConfigurableApplicationContext ctx = - new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); - + ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); ctx.refresh(); assertHasStandardEnvironment(ctx); @@ -134,8 +117,7 @@ public class EnvironmentIntegrationTests { @Test public void genericApplicationContext_customEnv() { - GenericApplicationContext ctx = - new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); + GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean()); ctx.setEnvironment(prodEnv); ctx.refresh(); @@ -191,11 +173,8 @@ public class EnvironmentIntegrationTests { @Test public void genericXmlApplicationContext() { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); - assertHasStandardEnvironment(ctx); - ctx.setEnvironment(prodEnv); - ctx.load(XML_PATH); ctx.refresh(); @@ -208,8 +187,7 @@ public class EnvironmentIntegrationTests { @Test public void classPathXmlApplicationContext() { - ConfigurableApplicationContext ctx = - new ClassPathXmlApplicationContext(new String[] { XML_PATH }); + ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH); ctx.setEnvironment(prodEnv); ctx.refresh(); @@ -228,7 +206,7 @@ public class EnvironmentIntegrationTests { // strange - FSXAC strips leading '/' unless prefixed with 'file:' ConfigurableApplicationContext ctx = - new FileSystemXmlApplicationContext(new String[] { "file:"+tmpFile.getPath() }, false); + new FileSystemXmlApplicationContext(new String[] {"file:" + tmpFile.getPath()}, false); ctx.setEnvironment(prodEnv); ctx.refresh(); assertEnvironmentBeanRegistered(ctx); @@ -588,7 +566,8 @@ public class EnvironmentIntegrationTests { try { ctx.refresh(); fail("expected missing property exception"); - } catch (MissingRequiredPropertiesException ex) { + } + catch (MissingRequiredPropertiesException ex) { } } @@ -598,7 +577,6 @@ public class EnvironmentIntegrationTests { ctx.setEnvironment(new MockEnvironment().withProperty("foo", "fooValue")); ctx.refresh(); // should succeed } - } @@ -652,6 +630,7 @@ public class EnvironmentIntegrationTests { assertThat(ctx.getBean(EnvironmentAwareBean.class).environment, is(expectedEnv)); } + private static class EnvironmentAwareBean implements EnvironmentAware { public Environment environment; @@ -660,9 +639,9 @@ public class EnvironmentIntegrationTests { public void setEnvironment(Environment environment) { this.environment = environment; } - } + /** * Mirrors the structure of beans and environment-specific config files * in EnvironmentIntegrationTests-context.xml @@ -711,4 +690,25 @@ public class EnvironmentIntegrationTests { return new Object(); } } + + + /** + * Constants used both locally and in scan* sub-packages + */ + public static class Constants { + + public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml"; + + public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean"; + + public static final String PROD_BEAN_NAME = "prodBean"; + public static final String DEV_BEAN_NAME = "devBean"; + public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean"; + public static final String TRANSITIVE_BEAN_NAME = "transitiveBean"; + + public static final String PROD_ENV_NAME = "prod"; + public static final String DEV_ENV_NAME = "dev"; + public static final String DERIVED_DEV_ENV_NAME = "derivedDev"; + } + }