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

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

提交回复
热议问题