with Java based configuration, i am trying to convert a map that maps enums to bean references to be in pure java config (currently in XML & works) but can’t seem to find anything in the documentations;
Currently, my XML like so;
<util:map id="colourHanders" key-type="com.example.ColourEnum"
value-type="com.example.ColourHandler">
<entry key="white" value-ref="whiteColourHandler"/>
<entry key="blue" value-ref="blueColourHandler"/>
<entry key="red" value-ref="redColourHandler"/>
</util:map>
I’m sure it is easy but again, can’t find anything on the subject of how to represent this in Pure Java (so I don’t have any XML configuration files)..
Note; the ColourHandler beans are created using the @Component annotation, e.g..
@Component
public class RedColourHandler implements ColourHander{
.....
}
and the map of colourHandlers is referenced as so;
@Resource(name="colourHandlers")
private Map<ColourHandlerEnum, ColourHandler> colourHandlers;
Thanks,
Ian.
You probably want something like this:
If you need to keep your handlers as
@Components, then you can autowire them into the configuration class: