You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Kathrin Baumgartner (JIRA)" <ji...@apache.org> on 2010/03/09 10:39:27 UTC

[jira] Created: (WICKET-2771) Please support "isPrimary" for @SpringBean

Please support "isPrimary" for @SpringBean
------------------------------------------

                 Key: WICKET-2771
                 URL: https://issues.apache.org/jira/browse/WICKET-2771
             Project: Wicket
          Issue Type: Improvement
          Components: wicket-spring
            Reporter: Kathrin Baumgartner


Our application must be adaptable for customer needs. We therefore need to be able to inject customer specific services. Since all our services are autowired, we could solve this by using the "primary" attribute. 

Our propsal is to patch SpringBeanLocator:

private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)  {
            // 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");
            } else if (names.size() > 1)   {
            ///////////////////////// add this ///////////////////////////////////////////////
                  for (String name : names){
                        BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name);
                        if(((AbstractBeanDefinition)beanDef).isPrimary()){
                             return name;
                        }
                  }
            //////////////////////////////////////////////////////////////////////////////////////

                  // found no match

                  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.toArray(new String[0])));
                  throw new IllegalStateException(msg.toString());
            }
            else{
                  return names.get(0);
            }
      }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2771) Please support "isPrimary" for @SpringBean

Posted by "Hudson (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12871428#action_12871428 ] 

Hudson commented on WICKET-2771:
--------------------------------

Integrated in Apache Wicket 1.5.x #68 (See [http://hudson.zones.apache.org/hudson/job/Apache%20Wicket%201.5.x/68/])
    Applied WICKET-2771


> Please support "isPrimary" for @SpringBean
> ------------------------------------------
>
>                 Key: WICKET-2771
>                 URL: https://issues.apache.org/jira/browse/WICKET-2771
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>            Reporter: Kathrin Baumgartner
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4.8, 1.5-M1
>
>
> Our application must be adaptable for customer needs. We therefore need to be able to inject customer specific services. Since all our services are autowired, we could solve this by using the "primary" attribute. 
> Our propsal is to patch SpringBeanLocator:
> private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)  {
>             // 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");
>             } else if (names.size() > 1)   {
>             ///////////////////////// add this ///////////////////////////////////////////////
>                   for (String name : names){
>                         BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name);
>                         if(((AbstractBeanDefinition)beanDef).isPrimary()){
>                              return name;
>                         }
>                   }
>             //////////////////////////////////////////////////////////////////////////////////////
>                   // found no match
>                   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.toArray(new String[0])));
>                   throw new IllegalStateException(msg.toString());
>             }
>             else{
>                   return names.get(0);
>             }
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (WICKET-2771) Please support "isPrimary" for @SpringBean

Posted by "Juergen Donnerstag (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/WICKET-2771?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Juergen Donnerstag resolved WICKET-2771.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.5-M1
                   1.4.8
         Assignee: Juergen Donnerstag

thanks

> Please support "isPrimary" for @SpringBean
> ------------------------------------------
>
>                 Key: WICKET-2771
>                 URL: https://issues.apache.org/jira/browse/WICKET-2771
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>            Reporter: Kathrin Baumgartner
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4.8, 1.5-M1
>
>
> Our application must be adaptable for customer needs. We therefore need to be able to inject customer specific services. Since all our services are autowired, we could solve this by using the "primary" attribute. 
> Our propsal is to patch SpringBeanLocator:
> private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)  {
>             // 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");
>             } else if (names.size() > 1)   {
>             ///////////////////////// add this ///////////////////////////////////////////////
>                   for (String name : names){
>                         BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name);
>                         if(((AbstractBeanDefinition)beanDef).isPrimary()){
>                              return name;
>                         }
>                   }
>             //////////////////////////////////////////////////////////////////////////////////////
>                   // found no match
>                   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.toArray(new String[0])));
>                   throw new IllegalStateException(msg.toString());
>             }
>             else{
>                   return names.get(0);
>             }
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2771) Please support "isPrimary" for @SpringBean

Posted by "Gerolf Seitz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12871399#action_12871399 ] 

Gerolf Seitz commented on WICKET-2771:
--------------------------------------

I applied the changes made to SpringBeanLocator also to AnnotProxyFieldValueFactory (in both 1.4.x and trunk), as the SpringComponentInjector uses AnnotProxyFieldValueFactory instead of SpringBeanLocator.

> Please support "isPrimary" for @SpringBean
> ------------------------------------------
>
>                 Key: WICKET-2771
>                 URL: https://issues.apache.org/jira/browse/WICKET-2771
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>            Reporter: Kathrin Baumgartner
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4.8, 1.5-M1
>
>
> Our application must be adaptable for customer needs. We therefore need to be able to inject customer specific services. Since all our services are autowired, we could solve this by using the "primary" attribute. 
> Our propsal is to patch SpringBeanLocator:
> private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)  {
>             // 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");
>             } else if (names.size() > 1)   {
>             ///////////////////////// add this ///////////////////////////////////////////////
>                   for (String name : names){
>                         BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name);
>                         if(((AbstractBeanDefinition)beanDef).isPrimary()){
>                              return name;
>                         }
>                   }
>             //////////////////////////////////////////////////////////////////////////////////////
>                   // found no match
>                   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.toArray(new String[0])));
>                   throw new IllegalStateException(msg.toString());
>             }
>             else{
>                   return names.get(0);
>             }
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2771) Please support "isPrimary" for @SpringBean

Posted by "Wojciech Grzybowski (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872246#action_12872246 ] 

Wojciech Grzybowski commented on WICKET-2771:
---------------------------------------------

Please note that line

BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name); 

will throw exception if bean is in parent application context.

Something similar to this method should help:

 private BeanDefinition getBeanDefinition(ConfigurableListableBeanFactory pBeanFactory, String pBeanName) {
        if (pBeanFactory.containsBeanDefinition(pBeanName)) {
            return pBeanFactory.getBeanDefinition(pBeanName);
        } else {
            BeanFactory parent = pBeanFactory.getParentBeanFactory();
            if (parent != null && parent instanceof ConfigurableListableBeanFactory) {
                return getBeanDefinition((ConfigurableListableBeanFactory) parent,pBeanName);
            } else {
                return null;
            }
        }
    }

> Please support "isPrimary" for @SpringBean
> ------------------------------------------
>
>                 Key: WICKET-2771
>                 URL: https://issues.apache.org/jira/browse/WICKET-2771
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>            Reporter: Kathrin Baumgartner
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4.8, 1.5-M1
>
>
> Our application must be adaptable for customer needs. We therefore need to be able to inject customer specific services. Since all our services are autowired, we could solve this by using the "primary" attribute. 
> Our propsal is to patch SpringBeanLocator:
> private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)  {
>             // 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");
>             } else if (names.size() > 1)   {
>             ///////////////////////// add this ///////////////////////////////////////////////
>                   for (String name : names){
>                         BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name);
>                         if(((AbstractBeanDefinition)beanDef).isPrimary()){
>                              return name;
>                         }
>                   }
>             //////////////////////////////////////////////////////////////////////////////////////
>                   // found no match
>                   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.toArray(new String[0])));
>                   throw new IllegalStateException(msg.toString());
>             }
>             else{
>                   return names.get(0);
>             }
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (WICKET-2771) Please support "isPrimary" for @SpringBean

Posted by "Gerolf Seitz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872891#action_12872891 ] 

Gerolf Seitz commented on WICKET-2771:
--------------------------------------

It would be great, if you could open a new jira issue for that.
thanks.

> Please support "isPrimary" for @SpringBean
> ------------------------------------------
>
>                 Key: WICKET-2771
>                 URL: https://issues.apache.org/jira/browse/WICKET-2771
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>            Reporter: Kathrin Baumgartner
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4.8, 1.5-M1
>
>
> Our application must be adaptable for customer needs. We therefore need to be able to inject customer specific services. Since all our services are autowired, we could solve this by using the "primary" attribute. 
> Our propsal is to patch SpringBeanLocator:
> private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)  {
>             // 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");
>             } else if (names.size() > 1)   {
>             ///////////////////////// add this ///////////////////////////////////////////////
>                   for (String name : names){
>                         BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name);
>                         if(((AbstractBeanDefinition)beanDef).isPrimary()){
>                              return name;
>                         }
>                   }
>             //////////////////////////////////////////////////////////////////////////////////////
>                   // found no match
>                   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.toArray(new String[0])));
>                   throw new IllegalStateException(msg.toString());
>             }
>             else{
>                   return names.get(0);
>             }
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (WICKET-2771) Please support "isPrimary" for @SpringBean

Posted by "Gerolf Seitz (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/WICKET-2771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12872891#action_12872891 ] 

Gerolf Seitz edited comment on WICKET-2771 at 5/28/10 8:13 PM:
---------------------------------------------------------------

see WICKET-2900

      was (Author: seitz):
    It would be great, if you could open a new jira issue for that.
thanks.
  
> Please support "isPrimary" for @SpringBean
> ------------------------------------------
>
>                 Key: WICKET-2771
>                 URL: https://issues.apache.org/jira/browse/WICKET-2771
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket-spring
>            Reporter: Kathrin Baumgartner
>            Assignee: Juergen Donnerstag
>             Fix For: 1.4.8, 1.5-M1
>
>
> Our application must be adaptable for customer needs. We therefore need to be able to inject customer specific services. Since all our services are autowired, we could solve this by using the "primary" attribute. 
> Our propsal is to patch SpringBeanLocator:
> private final String getBeanNameOfClass(ApplicationContext ctx, Class< ? > clazz)  {
>             // 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");
>             } else if (names.size() > 1)   {
>             ///////////////////////// add this ///////////////////////////////////////////////
>                   for (String name : names){
>                         BeanDefinition beanDef = ((AbstractApplicationContext)ctx).getBeanFactory().getBeanDefinition(name);
>                         if(((AbstractBeanDefinition)beanDef).isPrimary()){
>                              return name;
>                         }
>                   }
>             //////////////////////////////////////////////////////////////////////////////////////
>                   // found no match
>                   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.toArray(new String[0])));
>                   throw new IllegalStateException(msg.toString());
>             }
>             else{
>                   return names.get(0);
>             }
>       }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.