I am currently working on an application that utilizes microservices with Spring Boot. Although everything is functioning as expected, I am facing a minor issue with the Controllers.
Specifically, since one of the microservices is using packages from another, I had to utilize the following annotations in the second microservice (package names have been obfuscated):
@ComponentScan(basePackages = {"cm.test.p1","cm.test.p2"})
Now, p2 has its own Controllers package to expose its RESTful APIs. The problem I am facing is that Swagger for p1 is also displaying the Controllers in p2.
I have attempted to exclude the Controller package using the following annotation, but the issue still persists:
@ComponentScan(basePackages = {"cm.test.p1","cm.test.p2"}
, excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern="cm.test.p2.*Controller"))
and this
@ComponentScan(basePackages = {"cm.test.p1","cm.test.p2"},
excludeFilters=@ComponentScan.Filter(type = FilterType.ASPECTJ, pattern="cm.test.p2.*Controller+"))
Just to mention, I am using springdoc as the maven library.
Any guidance on how to address this issue would be greatly appreciated. Thank you!
It is possible to restrict the generated OpenAPI description using package or path configuration using application properties for springdoc
springdoc.packagesToScan=cm.test.p1
More information here