如何在 Micronaut 框架中从依赖项中注册控制器?

huangapple 未分类评论56阅读模式
英文:

How to register controllers from the dependencies in Micronaut Framework?

问题

我有一个微服务,我已经将它推送到了我的本地Artifactory服务中。它包含一些基本的端点,这些端点是所有其他Micronaut微服务所需的。我应该如何将这个依赖的控制器注册到父微服务中。

英文:

I have a micrount microservice which i have pushed in my local artifactory service. It contains come basic endpoints which are required for all the other micronaut microservices. How should I register the dependency's controllers to the parent microservices.

答案1

得分: 0

我更喜欢有2-3个JAR包(工具是可选的)

  • 一个用于应用本身
  • 一个用于API(仅接口和数据传输对象)
  • 一个用于工具(为API提供一些REST实现)

我还建议您看一下Micronaut声明性客户端
https://docs.micronaut.io/latest/guide/index.html#clientAnnotation 这可能会对您有很大帮助。

所以您有两个选项:

  • API和应用JAR包,并且只导入API JAR包作为您的依赖(您必须注意URL),这样您可能会陷入多次重新实现相同REST端点的困境
  • API、应用和工具JAR包,它将REST服务器和客户端委托给您的服务,并允许您一起维护它们,但如果您开始混合框架,例如Micronaut应用调用Spring Boot服务或类似情况,则会变得复杂。
英文:

i prefer to have 2-3 jars (util is optional)

  • one for the app itself
  • one for the api (only interfaces and dtos)
  • one for the util (to provide some rest implementations of the api)

i also suggest, that you have a look on the micronaut declarative client
https://docs.micronaut.io/latest/guide/index.html#clientAnnotation which propably helps you a lot.

So you have two options:

  • api and app jar and import for your dependencies only the api jar (you have to take care of the urls) and you probably get in trouble of reimplement the same rest endpoint several times
  • api, app and util jar which delegates the rest server and client to your service and allowes you to maintain them together this is difficult if you start mixing frameworks, e.g. a micronaut app is calling a spring boot service or something like that

huangapple
  • 本文由 发表于 2020年4月9日 19:53:37
  • 转载请务必保留本文链接:https://java.coder-hub.com/61120557.html
匿名

发表评论

匿名网友

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

确定