Jul 9th, 2012, 02:41 PM
ListableBeanFactory and Custom Annotations
Hi all, I have a situation where I have several implementation of a given Interface lets call it 'Transformer', previously the code contains a nasty nested logic block to give me the given type of class to work with.
One solution that I am toying with is to move this logic to a factory and utilise ListableBeanFactory to get me all the beans of type 'Transformer' then return the given bean dependent on the given criteria.
This works great but 2 values are required to determine the correct implementation e.g. version and type. To get over this I have created a custom annotation e.g. @TransformerVersion(version=5, type="internal") which means that when listing the beans of type 'Transformer' I can simple check the class for matedata matching both these values and then once matched return the bean.
My question is that this feels like a common(ish) thing to do and I imagine there may be something in Spring that already does this and will save me the logic of parsing the class annotations and matching this. I have had alook but cant find anything which looks appropriate, does anyone know of anything in spring which can perform this out of the box? It doesn't have to be annotation base but some form of adding metadata to a class and then return the bean from a factory dependent on these values?