【发布时间】:2018-11-29 20:26:16
【问题描述】:
我想为我的 spring_cloud_config_server 设置多个配置文件。
这是我的 yml 文件:
server:
port: "2000"
spring:
profiles:
active: native
application:
name: config-server
cloud:
config:
server:
native:
search-locations: file:///opt/app/configuration
eureka:
client:
service-url:
defaultZone: http://localhost:8260/eureka
logging:
level:
org:
springframework: INFO
---
spring:
profiles: docker
application:
name: config-server
cloud:
config:
server:
native:
search-locations: file:/opt/app/configuration
server:
port: "2000"
eureka:
client:
service-url:
defaultZone: http://127.0.0.1:8260/eureka
logging:
level:
org:
springframework: INFO
当我使用以下命令使用“本机”配置文件运行应用程序时
java -jar app.jar
或
java -jar -Dspring.profiles.active=native app.jar
应用运行良好。 当我使用以下命令使用“docker”配置文件运行应用程序时
java -jar -Dspring.profiles.active=docker app.jar
应用程序退出并出现异常:
ERROR o.s.b.w.e.tomcat.TomcatStarter - Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'configServerHealthIndicator' defined in class path resource [org/springframework/cloud/config/server/config/EnvironmentRepositoryConfiguration.class]: Unsatisfied dependency expressed through method 'configServerHealthIndicator' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.config.server.config.CompositeConfiguration': Unsatisfied dependency expressed through method 'setEnvironmentRepos' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultEnvironmentRepository' defined in class path resource [org/springframework/cloud/config/server/config/DefaultRepositoryConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: You need to configure a uri for the git repository.
根本原因是:
Exception: You need to configure a uri for the git repository.
我的 yml 文件对于这两个配置文件是否正确?我是否错过了任何使其适用于两个配置文件的内容?
【问题讨论】: