Issue with Swagger displaying Controllers in other microservice package

huangapple go评论93阅读模式
英文:

Issue with Swagger displaying Controllers in other microservice package

问题

我目前正在开发一个应用程序,它使用Spring Boot的微服务。尽管一切都按预期运行,但我在控制器方面遇到了一个小问题。

具体来说,由于其中一个微服务使用了另一个微服务的包,我不得不在第二个微服务中使用以下注释(包名已被混淆):

@ComponentScan(basePackages = {"cm.test.p1","cm.test.p2"})

现在,p2有自己的控制器包来暴露其RESTful API。我面临的问题是,Swagger也在p1中显示了p2的控制器。

我尝试使用以下注释来排除控制器包,但问题仍然存在:

@ComponentScan(basePackages = {"cm.test.p1","cm.test.p2"},
excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern="cm.test.p2.*Controller"))

以及这个:

@ComponentScan(basePackages = {"cm.test.p1","cm.test.p2"},
excludeFilters=@ComponentScan.Filter(type = FilterType.ASPECTJ, pattern="cm.test.p2.*Controller+"))

只是提一下,我正在使用springdoc作为Maven库。

如何解决这个问题的任何指导将不胜感激。谢谢!

英文:

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!

答案1

得分: 0

可以使用应用程序属性来限制生成的 OpenAPI 描述,通过包或路径配置 springdoc

springdoc.packagesToScan=cm.test.p1

更多信息这里

英文:

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

huangapple
  • 本文由 发表于 2023年4月11日 16:23:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75983821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定