Results 1 to 3 of 3

Thread: non-unique names with AnnotationBeanNameGenerator

  1. #1
    Join Date
    Aug 2004
    Posts
    230

    Default non-unique names with AnnotationBeanNameGenerator

    Why does AnnotationBeanNameGenerator use getClass.getSimpleName where in the xml if an id is omitted getClass.getName is used?

    This is causing me much grief, as components are overriding beans where multiples of the same type are desired.

    I know that I can specify a name-generator to component-scan, but that requires plugin modules (by developers possibly in other organizations) to "know" to do this for specific types. If they forget it can cause other plugins to faile -- not very api friendly.
    Barry Kaplan (memelet)

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Because when specifing no id in xml it is assumed this bean is going to be used nowhere and the name doesn't really matter. When using annotations and component-scanning it is assumed that the beans are used (and can be used in both xml/java/annotations) and need to have a meaningful (consistent) name.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2004
    Posts
    230

    Default

    Truly no no disrespect Marten, but that argument seems pretty weak to me. Xml beans and annotation beans seem fully symmetric in capabilities. Xml beans can be used in annotations just as annotation beans can be used in xml. If the name is important the @Bean annotation provides for optionally specifying a name, just as the 'id' attribute does for xml.

    In any case when auto-wiring by type, names may never be used. Yet it is typical (at least in my apps) to use autowire like:

    @Autowired var plugins: Array[SomeClassOfPlugin] = _

    But even with the below only one bean will remain in the context.

    @Configuration
    class MyConfig1 {
    @Bean p1 = new SomeClassOfPlugin
    }
    @Configuration
    class MyConfig2 {
    @Bean p2 = new SomeClassOfPlugin
    }
    Barry Kaplan (memelet)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •