Annotation-specified bean name conflicts with existing, non-compatible bean def

后端 未结 13 821
再見小時候
再見小時候 2021-01-31 01:51

I\'m having a problem with some Spring bean definitions. I have a couple of context xml files that are being loaded by my main() method, and both of them contain almost exclusiv

13条回答
  •  清歌不尽
    2021-01-31 02:08

    In an XML file, there is a sequence of declarations, and you may override a previous definition with a newer one. When you use annotations, there is no notion of before or after. All the beans are at the same level. You defined two beans with the same name, and Spring doesn't know which one it should choose.

    Give them a different name (staticConverterDAO, inMemoryConverterDAO for example), create an alias in the Spring XML file (theConverterDAO for example), and use this alias when injecting the converter:

    @Autowired @Qualifier("theConverterDAO")
    

提交回复
热议问题