Announcement Announcement Module
No announcement yet.
"Tagging" beans in XML to get specific bean by class and tag Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • "Tagging" beans in XML to get specific bean by class and tag


    I have big XML config made from several files.

    I need to get bean implementing specific interface. But there are several implementations so I have to choose. I want to tag bean with special "tag" to get it easily:

    <bean class="myInterfaceImpl1" tag="beanForMe"/>
    <bean class="myInterfaceImpl2"/>
    <bean class="myInterfaceImpl3"/>

    T get(Class<T> clazz) {
    return factory.getBean(clazz, "beanForMe"); //Returns first one

    Does there is something like that in spring?

    I found 2 workaround. First is to use special tag id:

    <bean class="myInterfaceImpl1" id="MyInterface-beanForMe"/>

    But when I rename class in My IDE everything would fail unless I write IDE plugin to support my idea.

    Second is to add all "tagged" beans to specific list, get it by id and then iterate through it to find appropriate bean.

    But tags would be the best here. What do you think?

  • #2
    I found solution:

    But we definitely need