You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2009/09/06 06:01:49 UTC
svn commit: r811755 -
/wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java
Author: ivaynberg
Date: Sun Sep 6 04:01:49 2009
New Revision: 811755
URL: http://svn.apache.org/viewvc?rev=811755&view=rev
Log:
WICKET-2444: Internal Spring beans should be ignored
Modified:
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java
Modified: wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java?rev=811755&r1=811754&r2=811755&view=diff
==============================================================================
--- wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java (original)
+++ wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/SpringBeanLocator.java Sun Sep 6 04:01:49 2009
@@ -17,6 +17,10 @@
package org.apache.wicket.spring;
import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import org.apache.wicket.proxy.IProxyTargetLocator;
import org.apache.wicket.util.lang.Classes;
@@ -103,25 +107,41 @@
*/
private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)
{
- String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ctx, clazz);
- if (names.length == 0)
+ // get the list of all possible matching beans
+ List<String> names = new ArrayList<String>(Arrays.asList(BeanFactoryUtils
+ .beanNamesForTypeIncludingAncestors(ctx, clazz)));
+ Iterator<String> it = names.iterator();
+
+ // filter out beans that are not condidates for autowiring
+ while (it.hasNext())
+ {
+ final String possibility = it.next();
+ if (BeanFactoryUtils.isFactoryDereference(possibility) ||
+ possibility.startsWith("scopedTarget."))
+ {
+ it.remove();
+ }
+ }
+
+ if (names.isEmpty())
{
throw new IllegalStateException("bean of type [" + clazz.getName() + "] not found");
}
- if (names.length > 1)
+ else if (names.size() > 1)
{
- StringBuffer msg = new StringBuffer();
+ StringBuilder msg = new StringBuilder();
msg.append("more then one bean of type [");
msg.append(clazz.getName());
msg.append("] found, you have to specify the name of the bean ");
msg.append("(@SpringBean(name=\"foo\")) in order to resolve this conflict. ");
-
msg.append("Matched beans: ");
- msg.append(Strings.join(",", names));
-
+ msg.append(Strings.join(",", names.toArray(new String[0])));
throw new IllegalStateException(msg.toString());
}
- return names[0];
+ else
+ {
+ return names.get(0);
+ }
}
/**