0

在 Spring Boot 中为应用程序 yaml 定义 AppProperties 的正确方法是什么?特别是对于component4-1, component4-2 & component4-3

app:   
  product:
    component1:
      baseUrl: http://localhost:8088
    component2:
      baseUrl: http://localhost:8080
    component3:
      baseUrl: http://localhost:8080
    component4:
      baseUrl: http://localhost:8080
      jwtToken: eyJraWQiOiJkZWZhdWx0IiwiYWxnIjoiUlM1MTIifQ.
      services:
        component4-1:
          baseUrl: http://localhost:8085
        component4-2:
          baseUrl: http://localhost:8086
        component4-3:
          baseUrl: http://localhost:8081
    component5:
      baseUrl: http://localhost:9080

我现在所做的是在 AppProperties 中定义 Service 类?

@Component
@ConfigurationProperties(prefix = "app.product")
class AppProperties {

    val component1 = Service()
    val component2 = Service()
    val component3 = Service()
    val component4 = Componenet4Properties()
    val component5 = Service()

    class Service {
        lateinit var baseUrl: String
        lateinit var jwtToken: String
    }
    
    class Componenet4Properties {
        var component4_1 = Service()
    }

}
4

0 回答 0