diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java index 8c73a16fd7..7d65a3aaf4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactory.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. @@ -170,8 +170,7 @@ public interface BeanFactory { *

Allows for specifying explicit constructor arguments / factory method arguments, * overriding the specified default arguments (if any) in the bean definition. * @param name the name of the bean to retrieve - * @param args arguments to use if creating a prototype using explicit arguments to a - * static factory method. It is invalid to use a non-null args value in any other case. + * @param args arguments to use if creating a prototype using explicit arguments * @return an instance of the bean * @throws NoSuchBeanDefinitionException if there is no such bean definition * @throws BeanDefinitionStoreException if arguments have been given but diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 04ec97c301..597ba82dcd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -236,7 +236,8 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean Annotation annotation = findAutowiredAnnotation(candidate); if (annotation != null) { if (requiredConstructor != null) { - throw new BeanCreationException("Invalid autowire-marked constructor: " + candidate + + throw new BeanCreationException(beanName, + "Invalid autowire-marked constructor: " + candidate + ". Found another constructor with 'required' Autowired annotation: " + requiredConstructor); } @@ -247,10 +248,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean boolean required = determineRequiredStatus(annotation); if (required) { if (!candidates.isEmpty()) { - throw new BeanCreationException( + throw new BeanCreationException(beanName, "Invalid autowire-marked constructors: " + candidates + ". Found another constructor with 'required' Autowired annotation: " + - requiredConstructor); + candidate); } requiredConstructor = candidate; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java index d3ba877f31..bd511bf10d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.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. @@ -1228,7 +1228,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp // Check validity of the usage of the args parameter. This can // only be used for prototypes constructed via a factory method. if (args != null && !mbd.isPrototype()) { - throw new BeanDefinitionStoreException( + throw new BeanDefinitionStoreException(mbd.getResourceDescription(), beanName, "Can only specify arguments for the getBean method when referring to a prototype bean definition"); } } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java index fef8fde389..076e209838 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategy.java @@ -33,8 +33,9 @@ import org.springframework.cglib.proxy.NoOp; /** * Default object instantiation strategy for use in BeanFactories. - * Uses CGLIB to generate subclasses dynamically if methods need to be - * overridden by the container, to implement Method Injection. + * + *

Uses CGLIB to generate subclasses dynamically if methods need to be + * overridden by the container to implement Method Injection. * * @author Rod Johnson * @author Juergen Hoeller @@ -50,13 +51,13 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt /** * Index in the CGLIB callback array for a method that should - * be overridden to provide method lookup. + * be overridden to provide method lookup. */ private static final int LOOKUP_OVERRIDE = 1; /** * Index in the CGLIB callback array for a method that should - * be overridden using generic Methodreplacer functionality. + * be overridden using generic method replacer functionality. */ private static final int METHOD_REPLACER = 2; @@ -96,13 +97,13 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt } /** - * Create a new instance of a dynamically generated subclasses implementing the + * Create a new instance of a dynamically generated subclass implementing the * required lookups. * @param ctor constructor to use. If this is {@code null}, use the * no-arg constructor (no parameterization, or Setter Injection) * @param args arguments to use for the constructor. - * Ignored if the ctor parameter is {@code null}. - * @return new instance of the dynamically generated class + * Ignored if the {@code ctor} parameter is {@code null}. + * @return new instance of the dynamically generated subclass */ public Object instantiate(Constructor ctor, Object[] args) { Enhancer enhancer = new Enhancer(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java index 560943d309..6aa560ce01 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/LookupOverride.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. @@ -37,10 +37,9 @@ public class LookupOverride extends MethodOverride { /** * Construct a new LookupOverride. - * @param methodName the name of the method to override. - * This method must have no arguments. - * @param beanName name of the bean in the current BeanFactory - * that the overriden method should return + * @param methodName the name of the method to override + * @param beanName the name of the bean in the current BeanFactory + * that the overridden method should return */ public LookupOverride(String methodName, String beanName) { super(methodName); @@ -48,6 +47,7 @@ public class LookupOverride extends MethodOverride { this.beanName = beanName; } + /** * Return the name of the bean that should be returned by this method. */ @@ -55,9 +55,8 @@ public class LookupOverride extends MethodOverride { return this.beanName; } - /** - * Match method of the given name, with no parameters. + * Match the method of the given name, with no parameters. */ @Override public boolean matches(Method method) { @@ -65,11 +64,6 @@ public class LookupOverride extends MethodOverride { } - @Override - public String toString() { - return "LookupOverride for method '" + getMethodName() + "'; will return bean '" + this.beanName + "'"; - } - @Override public boolean equals(Object other) { return (other instanceof LookupOverride && super.equals(other) && @@ -81,4 +75,9 @@ public class LookupOverride extends MethodOverride { return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.beanName)); } + @Override + public String toString() { + return "LookupOverride for method '" + getMethodName() + "'; will return bean '" + this.beanName + "'"; + } + } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java index 4e5d4c3a90..33f969db4f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java @@ -52,6 +52,7 @@ public abstract class MethodOverride implements BeanMetadataElement { this.methodName = methodName; } + /** * Return the name of the method to be overridden. */ @@ -98,6 +99,7 @@ public abstract class MethodOverride implements BeanMetadataElement { */ public abstract boolean matches(Method method); + @Override public boolean equals(Object other) { if (this == other) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index e570a24c57..55ef696b59 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.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. @@ -52,6 +52,7 @@ public class ReplaceOverride extends MethodOverride { this.methodReplacerBeanName = methodReplacerBeanName; } + /** * Return the name of the bean implementing MethodReplacer. */ @@ -68,28 +69,22 @@ public class ReplaceOverride extends MethodOverride { this.typeIdentifiers.add(identifier); } - @Override public boolean matches(Method method) { - // TODO could cache result for efficiency if (!method.getName().equals(getMethodName())) { - // It can't match. return false; } - if (!isOverloaded()) { - // No overloaded: don't worry about arg type matching. + // Not overloaded: don't worry about arg type matching... return true; } - - // If we get to here, we need to insist on precise argument matching. + // If we get here, we need to insist on precise argument matching... if (this.typeIdentifiers.size() != method.getParameterTypes().length) { return false; } for (int i = 0; i < this.typeIdentifiers.size(); i++) { String identifier = this.typeIdentifiers.get(i); if (!method.getParameterTypes()[i].getName().contains(identifier)) { - // This parameter cannot match. return false; } } @@ -97,12 +92,6 @@ public class ReplaceOverride extends MethodOverride { } - @Override - public String toString() { - return "Replace override for method '" + getMethodName() + "; will call bean '" + - this.methodReplacerBeanName + "'"; - } - @Override public boolean equals(Object other) { if (!(other instanceof ReplaceOverride) || !super.equals(other)) { @@ -121,4 +110,10 @@ public class ReplaceOverride extends MethodOverride { return hashCode; } + @Override + public String toString() { + return "Replace override for method '" + getMethodName() + "; will call bean '" + + this.methodReplacerBeanName + "'"; + } + } diff --git a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java index a5bc212ced..242cb21f7b 100644 --- a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.java +++ b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTestTypes.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. @@ -27,24 +27,26 @@ import java.util.Set; import javax.sql.DataSource; import org.springframework.beans.BeansException; -import org.springframework.tests.sample.beans.ITestBean; -import org.springframework.tests.sample.beans.IndexedTestBean; -import org.springframework.tests.sample.beans.TestBean; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; -import org.springframework.tests.sample.beans.factory.DummyFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.support.MethodReplacer; +import org.springframework.tests.sample.beans.ITestBean; +import org.springframework.tests.sample.beans.IndexedTestBean; +import org.springframework.tests.sample.beans.TestBean; +import org.springframework.tests.sample.beans.factory.DummyFactory; /** * Types used by {@link XmlBeanFactoryTests} and its attendant XML config files. * * @author Chris Beams */ -final class XmlBeanFactoryTestTypes { } +final class XmlBeanFactoryTestTypes { +} + /** * Simple bean used to check constructor dependency checking. @@ -174,18 +176,12 @@ abstract class ConstructorInjectedOverrides { return this.tb; } - protected abstract FactoryMethods createFactoryMethods(); - /** - * @return Returns the setterString. - */ public String getSetterString() { return setterString; } - /** - * @param setterString The setterString to set. - */ + public void setSetterString(String setterString) { this.setterString = setterString; } @@ -229,7 +225,6 @@ class DerivedConstructorDependenciesBean extends ConstructorDependenciesBean { private void destroy() { this.destroyed = true; } - } @@ -240,7 +235,6 @@ class DerivedConstructorDependenciesBean extends ConstructorDependenciesBean { interface DummyBo { void something(); - } @@ -258,9 +252,7 @@ class DummyBoImpl implements DummyBo { @Override public void something() { - } - } @@ -274,7 +266,6 @@ class DummyDao { public DummyDao(DataSource ds) { this.ds = ds; } - } @@ -290,7 +281,6 @@ class DummyReferencer { private DummyFactory dummyFactory; - public DummyReferencer() { } @@ -321,7 +311,6 @@ class DummyReferencer { public TestBean getTestBean2() { return testBean2; } - } @@ -370,13 +359,11 @@ class FactoryMethods { return Collections.EMPTY_LIST; } - private int num = 0; private String name = "default"; private TestBean tb; private String stringValue; - /** * Constructor is private: not for use outside this class, * even by IoC container. @@ -421,7 +408,6 @@ class FactoryMethods { public void setName(String name) { this.name = name; } - } /** @@ -436,7 +422,6 @@ class FixedMethodReplacer implements MethodReplacer { public Object reimplement(Object obj, Method method, Object[] args) throws Throwable { return VALUE; } - } @@ -469,22 +454,17 @@ class MethodReplaceCandidate { public String replaceMe(String echo) { return echo; } - } /** * Bean that exposes a simple property that can be set * to a mix of references and individual values. - * - * @author Rod Johnson - * @since 27.05.2003 */ class MixedCollectionBean { private Collection jumble; - public void setJumble(Collection jumble) { this.jumble = jumble; } @@ -492,7 +472,6 @@ class MixedCollectionBean { public Collection getJumble() { return jumble; } - } @@ -504,7 +483,6 @@ interface OverrideInterface { TestBean getPrototypeDependency(); TestBean getPrototypeDependency(Object someParam); - } @@ -521,7 +499,7 @@ abstract class OverrideOneMethod extends MethodReplaceCandidate implements Overr return new TestBean(); } - public TestBean invokesOverridenMethodOnSelf() { + public TestBean invokesOverriddenMethodOnSelf() { return getPrototypeDependency(); } @@ -563,7 +541,6 @@ abstract class OverrideOneMethodSubclass extends OverrideOneMethod { // This implementation does nothing! // It's not overloaded } - } @@ -591,7 +568,6 @@ class ProtectedLifecycleBean implements BeanNameAware, BeanFactoryAware, Initial protected boolean destroyed; - public void setInitMethodDeclared(boolean initMethodDeclared) { this.initMethodDeclared = initMethodDeclared; } @@ -707,7 +683,6 @@ class ProtectedLifecycleBean implements BeanNameAware, BeanFactoryAware, Initial return bean; } } - } @@ -722,7 +697,6 @@ class ReverseMethodReplacer implements MethodReplacer, Serializable { String s = (String) args[0]; return new StringBuffer(s).reverse().toString(); } - } @@ -733,7 +707,6 @@ class ReverseMethodReplacer implements MethodReplacer, Serializable { abstract class SerializableMethodReplacerCandidate extends MethodReplaceCandidate implements Serializable { //public abstract Point getPoint(); - } @@ -769,5 +742,4 @@ class SingleSimpleTypeConstructorBean { public String getTestString() { return testString; } - } diff --git a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java index 1eb796d655..b1dafd1fb8 100644 --- a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java +++ b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java @@ -1379,7 +1379,7 @@ public final class XmlBeanFactoryTests { // This differs from Spring's AOP support, which has a distinct notion // of a "target" object, meaning that the target needs explicit knowledge // of AOP proxying to invoke an advised method on itself. - TestBean jenny3 = oom.invokesOverridenMethodOnSelf(); + TestBean jenny3 = oom.invokesOverriddenMethodOnSelf(); assertEquals("Jenny", jenny3.getName()); assertNotSame(jenny1, jenny3); diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index 17c391d465..502d682740 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -495,8 +495,7 @@ public abstract class ReflectionUtils { mc.doWith(method); } catch (IllegalAccessException ex) { - throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() - + "': " + ex); + throw new IllegalStateException("Shouldn't be illegal to access method '" + method.getName() + "': " + ex); } } if (clazz.getSuperclass() != null) { @@ -605,8 +604,7 @@ public abstract class ReflectionUtils { fc.doWith(field); } catch (IllegalAccessException ex) { - throw new IllegalStateException( - "Shouldn't be illegal to access field '" + field.getName() + "': " + ex); + throw new IllegalStateException("Shouldn't be illegal to access field '" + field.getName() + "': " + ex); } } targetClass = targetClass.getSuperclass(); @@ -628,8 +626,8 @@ public abstract class ReflectionUtils { throw new IllegalArgumentException("Destination for field copy cannot be null"); } if (!src.getClass().isAssignableFrom(dest.getClass())) { - throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() - + "] must be same or subclass as source class [" + src.getClass().getName() + "]"); + throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() + + "] must be same or subclass as source class [" + src.getClass().getName() + "]"); } doWithFields(src.getClass(), new FieldCallback() { public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {