Spring boot 向application.properties Spring Boot应用程序添加环境变量

Spring boot 向application.properties Spring Boot应用程序添加环境变量,spring-boot,Spring Boot,我需要使用环境变量将application.properties中设置的参数外部化。 这是我的application.properties文件: spring.datasource.url= jdbc:mysql://${MYSQL_URL}:${MYSQL_PORT}/${MYSQL_DBNAME} spring.datasource.username= ${MYSQL_USERNAME} spring.datasource.password= ${MYSQL_PASSWORD} spring

我需要使用环境变量将application.properties中设置的参数外部化。 这是我的application.properties文件:

spring.datasource.url= jdbc:mysql://${MYSQL_URL}:${MYSQL_PORT}/${MYSQL_DBNAME}
spring.datasource.username= ${MYSQL_USERNAME}
spring.datasource.password= ${MYSQL_PASSWORD}
spring.datasource.driver-class-name= com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.MySQL5Dialect
这些${--}是环境变量。 但当我尝试运行我的应用程序时,会出现以下错误:

Property: spring.datasource.url
    Value: jdbc:mysql://${MYSQL_URL}:${MYSQL_PORT}/${MYSQL_DBNAME}
    Origin: class path resource [application.properties]:1:24
    Reason: Could not resolve placeholder 'MYSQL_URL' in value "jdbc:mysql://${MYSQL_URL}:${MYSQL_PORT}/${MYSQL_DBNAME}"

我发现环境变量是在我启动Eclipse之后定义的,Eclipse无法识别它们,因此解决方案很简单:重新启动Eclipse