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

后端 未结 13 815
再見小時候
再見小時候 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:03

    Using Eclipse, I had moved classes into new packages, and was getting this error. What worked for me was doing: Project > Clean

    and also cleaning my TomCat server by right-clicking on it and selecting clean

    Thanks to Rock Lee's answer for helping me figure it out :)

    0 讨论(0)
  • 2021-01-31 02:05

    Sometimes the problem occurs if you have moved your classes around and it refers to old classes, even if they don't exist.

    In this case, just do this :

    mvn eclipse:clean
    
    mvn eclipse:eclipse
    

    This worked well for me.

    0 讨论(0)
  • 2021-01-31 02:06

    If none of the other answers fix your problem and it started occurring after change any configuration direct or indirectly (via git pull / merge / rebase) and your project is a Maven project:

    mvn clean
    

    Hope this fixes your problem. Or someones

    0 讨论(0)
  • 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")
    
    0 讨论(0)
  • 2021-01-31 02:10

    I had a similar issue with Spring 4.x using @RestController. Two different packages had a class with the same name...

    package com.x.catalog
    
    @RestController
    public class TextureController {
    ...
    
    package com.x.cms
    @RestController
    public class TextureController {
    ...
    

    The fix was easy...

    package com.x.catalog
    
    @RestController("CatalogTextureController")
    public class TextureController {
    ...
    
    package com.x.cms
    @RestController("CMSTextureController")
    public class TextureController {
    ...
    

    The problem seems to be that the annotation gets autowired and takes the class name by default. Giving it an explicit name in the @RestController annotation allows you to keep the class names.

    0 讨论(0)
  • 2021-01-31 02:10

    I had the same issue. I solved it by using the following steps(Editor: IntelliJ):

    1. View -> Tool Windows -> Maven Project. Opens your projects in a sub-window.
    2. Click on the arrow next to your project.
    3. Click on the lifecycle.
    4. Click on clean.
    0 讨论(0)
提交回复
热议问题