【问题标题】:How to create Jar library file which automatically creates rest api endpoints to a spring boot application?如何创建自动为 Spring Boot 应用程序创建 rest api 端点的 Jar 库文件?
【发布时间】:2018-04-09 17:52:44
【问题描述】:

我想创建一个库 jar 文件。当我将它带到 spring-boot 应用程序时,它应该使应用程序具有 Rest API 端点,而不向 spring-boot 应用程序添加任何 @RestController。

例如,我想创建custom-oauth.jar 库。当我将custom-oauth.jar 包含到spring-boot 应用程序中时,该应用程序应该有http://localhost/tokenhttp://localhost/validate ...等。

我知道这是 Spring 应用程序的一个非常常见的情况,并且有很多 jar 文件可以执行此操作,但我在 Spring 文档中找不到如何实现。

我应该从哪里开始阅读以及应该使用哪些工具?

【问题讨论】:

    标签: java spring spring-boot


    【解决方案1】:

    在引导应用程序中执行此操作的最直接方法是write your own autoconfiguration module。简而言之,您创建一个或多个“引导”@Configuration 类并将它们列在META-INF/spring.factories 中。然后,他们可以执行您通常会执行的任何类型的操作(例如为 jar 中包含的控制器类注册 @Beans 或 @ComponentScans)。

    【讨论】:

      猜你喜欢
      • 2017-07-04
      • 2016-06-05
      • 2021-10-20
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      相关资源
      最近更新 更多