0

Let's say I have following classes

.../RabbitController
.../test/SomeController

springfox, without any swagger annotations, works fine.

rabbit-controller
some-controller

When I add another class

.../RabbitController
.../test/SomeController
.../test/RabbitController

An error comes out,

Annotation-specified bean name 'rabbitController'
for bean class [...RabbitController]
conflicts with existing,
non-compatible bean definition of same name and class
[.....test.RabbitController]

Is there any way to make springfox be aware of the hierarchy of the class so that I get something like

rabbit-controller
test-some-controller
test-rabbit-controller

?

Jin Kwon
  • 20,295
  • 14
  • 115
  • 184

1 Answers1

1

Spring

  • Spring will complain if you have two controllers of the same name. Spring names an autodetected component such as a bean marked with @RestController as an uncapitalized non-qualified class name in the absence of a name value.
  • You can avoid the following error by naming the second RabbitController as @RestController("test-rabbit-controller"). You can find more information 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

From the perspective of Springfox, you can make both the controllers distinct by having distinct description value in the @Api annotation.

Here are the changes you need to make:

Controller 1

@RestController
@Slf4j
@Api(description = "rabbit-controller",
        produces = "application/json", tags = {"1"})
public class RabbitController {
    ...
}

Controller 2

@RestController("test-rabbit-controller")
@Slf4j
@Api(description = "test-rabbit-controller",
        produces = "application/json", tags = {"2"})
public class RabbitController {
    ...
}

enter image description here

Indra Basak
  • 7,124
  • 1
  • 26
  • 45