如何为开发属性禁用 spring-cloud 配置服务器
How to disable spring-cloud config server for dev properties
我将 spring 云集成到我的 spring 应用程序中。它工作正常。但我有 3 个属性文件:
application.properties
server.port 9101
spring.profiles.active=@env@
logging.level.org.springframework.data=debug
logging.level.=error
申请-dev.properties
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.hibernate.use-new-id-generator-mappings=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
#TRACE DEBUG or INFO
logging.level.org.hibernate.type=INFO
spring.application.name=microservice-payment
spring.cloud.config.enabled = false
spring.jpa.properties.hibernate.type=trace
spring.datasource.url=jdbc:postgresql://localhost:5432/gara-mpayment
spring.datasource.username=garauser
spring.datasource.password=garauser
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.initialization-mode=always
server.servlet.session.timeout=10s
#RabbitMq configuration
rabbitmq.queueName=mpayment.queue
rabbitmq.exchangeName=mpayment-exchange
rabbitmq.routingKey=mpayment.routingkey
和应用-int.properties
spring.cloud.config.server.git.uri=my-url
spring.cloud.config.server.git.username=username
spring.cloud.config.server.git.password=pwd
我可以为开发配置文件禁用 spring 云,以便使用 application-dev.properties 的本地内容并仅为 applictaion-int.properties 激活吗?
我试过 spring.cloud.config.enabled=false
spring.cloud.bootstrap.enabled=false
没有成功。
您应该创建一个 bootstrap.yml 或属性文件并添加 spring.cloud.config.enable=false
或设置环境变量并禁用 spring 云
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html
您提到的错误请参考上述linkInvalid config server configuration. Action: If you are using the git profile, you need to set a Git URI in your configuration. If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration
您可以在这里找到解决方案:https://github.com/spring-cloud/spring-cloud-config/issues/1503#event-2910814394
@Configuration
@ConditionalOnMissingBean(EnvironmentRepository.class)
@Profile("dev") // profile name
class NativeRepositoryConfiguration {
@Bean
public NativeEnvironmentRepository nativeEnvironmentRepository(NativeEnvironmentRepositoryFactory factory,
NativeEnvironmentProperties environmentProperties) {
return factory.build(environmentProperties);
}
}
我将 spring 云集成到我的 spring 应用程序中。它工作正常。但我有 3 个属性文件: application.properties
server.port 9101
spring.profiles.active=@env@
logging.level.org.springframework.data=debug
logging.level.=error
申请-dev.properties
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.hibernate.use-new-id-generator-mappings=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
#TRACE DEBUG or INFO
logging.level.org.hibernate.type=INFO
spring.application.name=microservice-payment
spring.cloud.config.enabled = false
spring.jpa.properties.hibernate.type=trace
spring.datasource.url=jdbc:postgresql://localhost:5432/gara-mpayment
spring.datasource.username=garauser
spring.datasource.password=garauser
spring.jpa.hibernate.ddl-auto=update
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.initialization-mode=always
server.servlet.session.timeout=10s
#RabbitMq configuration
rabbitmq.queueName=mpayment.queue
rabbitmq.exchangeName=mpayment-exchange
rabbitmq.routingKey=mpayment.routingkey
和应用-int.properties
spring.cloud.config.server.git.uri=my-url
spring.cloud.config.server.git.username=username
spring.cloud.config.server.git.password=pwd
我可以为开发配置文件禁用 spring 云,以便使用 application-dev.properties 的本地内容并仅为 applictaion-int.properties 激活吗?
我试过 spring.cloud.config.enabled=false
spring.cloud.bootstrap.enabled=false
没有成功。
您应该创建一个 bootstrap.yml 或属性文件并添加 spring.cloud.config.enable=false
或设置环境变量并禁用 spring 云
https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html
您提到的错误请参考上述linkInvalid config server configuration. Action: If you are using the git profile, you need to set a Git URI in your configuration. If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration
您可以在这里找到解决方案:https://github.com/spring-cloud/spring-cloud-config/issues/1503#event-2910814394
@Configuration
@ConditionalOnMissingBean(EnvironmentRepository.class)
@Profile("dev") // profile name
class NativeRepositoryConfiguration {
@Bean
public NativeEnvironmentRepository nativeEnvironmentRepository(NativeEnvironmentRepositoryFactory factory,
NativeEnvironmentProperties environmentProperties) {
return factory.build(environmentProperties);
}
}