Gradle 与云的 SpringBoot 配置文件
SpringBoot profiles with Gradle vs cloud
我在本地机器上使用云配置启动微服务时遇到一些问题:
在 application.yml:
spring:
application:
name: my_servie
config:
import: 'configserver:'
profiles:
group:
env-prod-pg: postgres,log
我创建应用程序-local.yml,其中添加:
spring:
application:
name: mc-service-logistics-v2
config:
import: 'optional:configserver:'
和其他一些配置更新,
在 build.gradle 我添加:
tasks.register("bootRunLocal") {
group = "application"
description = "Runs the Spring Boot application with the local profile"
doFirst {
tasks.bootRun.configure {
systemProperty("spring.profiles.active", "local")
}
}
finalizedBy("bootRun")
}
但是当我尝试使用 gradle bootRunLocal 启动应用程序时,我遇到了错误:
由以下原因引起:org.springframework.web.client.ResourceAccessException:“http://localhost:8888/my-service/local”的 GET 请求出现 I/O 错误:连接被拒绝;嵌套异常是 java.net.ConnectException:连接被拒绝
据我了解- 应用程序仍要使用云配置且无法启动。如果我评论
spring.config.import 在 application.yml- 应用程序启动没有任何问题。
如何解决这个问题?我不想再次推送回购我的本地配置)
好吧,我创建到 application-.yml 和 application.yml,其中存储当前配置文件:
spring:
profiles:
active: prod
我在本地机器上使用云配置启动微服务时遇到一些问题: 在 application.yml:
spring:
application:
name: my_servie
config:
import: 'configserver:'
profiles:
group:
env-prod-pg: postgres,log
我创建应用程序-local.yml,其中添加:
spring:
application:
name: mc-service-logistics-v2
config:
import: 'optional:configserver:'
和其他一些配置更新, 在 build.gradle 我添加:
tasks.register("bootRunLocal") {
group = "application"
description = "Runs the Spring Boot application with the local profile"
doFirst {
tasks.bootRun.configure {
systemProperty("spring.profiles.active", "local")
}
}
finalizedBy("bootRun")
}
但是当我尝试使用 gradle bootRunLocal 启动应用程序时,我遇到了错误: 由以下原因引起:org.springframework.web.client.ResourceAccessException:“http://localhost:8888/my-service/local”的 GET 请求出现 I/O 错误:连接被拒绝;嵌套异常是 java.net.ConnectException:连接被拒绝
据我了解- 应用程序仍要使用云配置且无法启动。如果我评论 spring.config.import 在 application.yml- 应用程序启动没有任何问题。
如何解决这个问题?我不想再次推送回购我的本地配置)
好吧,我创建到 application-.yml 和 application.yml,其中存储当前配置文件:
spring:
profiles:
active: prod