Spring boot 如何从Spring启动代码中读取Gitlab(.Gitlab-ci.yml)环境变量?
在构建应用程序时,我试图读取从Gitlab配置中设置的环境变量,我这样做是为了达到这个目的: 我在spring boot应用程序的application.properties.yml中设置了一个变量:Spring boot 如何从Spring启动代码中读取Gitlab(.Gitlab-ci.yml)环境变量?,spring-boot,kotlin,gitlab,environment-variables,gitlab-ci,Spring Boot,Kotlin,Gitlab,Environment Variables,Gitlab Ci,在构建应用程序时,我试图读取从Gitlab配置中设置的环境变量,我这样做是为了达到这个目的: 我在spring boot应用程序的application.properties.yml中设置了一个变量: sf: apiKey: $SF_API_KEY 在.gitlab-ci.yml中,我定义了要设置的变量,如下所示: variables: SF_API_KEY: $SF_API_KEY 我只想能够从我的一个服务中读取该变量,如下代码所示: @Service class MyService
sf:
apiKey: $SF_API_KEY
在.gitlab-ci.yml中,我定义了要设置的变量,如下所示:
variables:
SF_API_KEY: $SF_API_KEY
我只想能够从我的一个服务中读取该变量,如下代码所示:
@Service
class MyService(@Value("\${sf.apiKey}") val apiKey: String)
{
fun doSomething(){
//i am seeing the variable is being set by gitlab in the build logs but
// it is not being read here properly
var result = apiKey;
logger.info { "***check apiKey: $apiKey" }
//This line lgs $SF_API_KEY as a value of my variable, but not the
// real value
}
}
我做错什么了吗?如果有任何帮助,我将不胜感激。请尝试(注意SF\u API\u键周围的{}
):
查看此占位符符号的详细位置。尝试(注意SF\u API\u键周围的{}
):
看一看这个占位符符号的详细位置
sf:
apiKey: ${SF_API_KEY}