我们说我有以下课程
.../RabbitController
.../test/SomeController
springfox,没有任何招摇的注释,工作正常。
rabbit-controller
some-controller
当我添加另一个类
时.../RabbitController
.../test/SomeController
.../test/RabbitController
出现错误,
Annotation-specified bean name 'rabbitController'
for bean class [...RabbitController]
conflicts with existing,
non-compatible bean definition of same name and class
[.....test.RabbitController]
有没有办法让springfox知道类的层次结构,以便我得到像
这样的东西rabbit-controller
test-some-controller
test-rabbit-controller
答案 0 :(得分:1)
@RestController
值的情况下,Spring将自动检测的组件(例如标有uncapitalized non-qualified class name
的bean)命名为name
。 RabbitController
命名为@RestController("test-rabbit-controller")
来避免以下错误。您可以找到更多信息here。
Annotation-specified bean name 'rabbitController'
for bean class [...RabbitController]
conflicts with existing,
non-compatible bean definition of same name and class
[.....test.RabbitController]
从Springfox的角度来看,您可以通过在description
注释中使用不同的@Api
值来使两个控制器区别开来。
以下是您需要进行的更改:
@RestController
@Slf4j
@Api(description = "rabbit-controller",
produces = "application/json", tags = {"1"})
public class RabbitController {
...
}
@RestController("test-rabbit-controller")
@Slf4j
@Api(description = "test-rabbit-controller",
produces = "application/json", tags = {"2"})
public class RabbitController {
...
}