标签: spring-cloud-config

使用Spring Cloud Config而不使用Git repo

是否可以在不使用任何Git仓库的情况下使用Spring Cloud Config?我正在尝试使用application.properties中的本地目录来测试它:

spring.cloud.config.server.git.uri=file://${user.dir}/src/main/resources/config-repo

但是我收到以下错误:

java.lang.IllegalStateException:文件中没有.git:// path/to/src/main/resources/config-repo

如果一个人根本不使用Git,那么就不可能使用Spring Cloud吗?

更新:

感谢Spencer的建议,我补充了以下内容:

spring.profiles.active=native spring.cloud.config.server.native.searchLocations=${user.dir}/src/main/resources/configs

我在"configs"中有一个文件"bar.properties",其中包含以下内容:

foo: bar
Run Code Online (Sandbox Code Playgroud)

但我得到的反应不是读取文件:

{
  "name": "bar",
  "profiles": [
    "default"
  ],
  "label": "master",
  "propertySources": []
}
Run Code Online (Sandbox Code Playgroud)

我正在使用的URL是http:// localhost:8888/bar/default

我错过了别的什么吗?再次感谢您!

java spring spring-cloud spring-cloud-config

27
推荐指数
3
解决办法
2万
查看次数

了解Spring Cloud版本

春天的人们在发布大量优质项目方面做得很好.我们一直在使用的是Spring Cloud及其各个子项目.

一个令我困惑的方面是Spring Cloud版本名称.例如,如果您转到Spring Cloud,它会读取CamdenAngelBrixton.然后,如果你转到特定的项目站点,例如,Spring Cloud Config它会显示像1.3.0或的版本1.2.3

关于这些的两个问题.

  1. 从命名版本(camden,brixton,angel)来看,很难看出哪个是最新版本及其序列.有没有一个记录良好的地方?

  2. 如何将命名版本与子项目编号发布相关联?

感谢您的时间.

spring-cloud spring-cloud-config

18
推荐指数
2
解决办法
4449
查看次数

没有定义 spring.config.import 属性

在创建 Spring Boot 云配置应用程序时出现以下错误。这有什么帮助吗?

没有定义 spring.config.import 属性

行动:

将 spring.config.import=configserver: 属性添加到您的配置中。如果不需要配置,请添加 spring.config.import=optional:configserver: 代替。要禁用此检查,请设置 spring.cloud.config.enabled=false 或 spring.cloud.config.import-check.enabled=false。

spring-cloud-config

18
推荐指数
6
解决办法
2万
查看次数

如何在引导程序文件中正确设置不同的Spring配置文件(Spring Boot以不同的Cloud Config服务器为目标)?

每个环境都有不同的配置服务器.每个Spring启动应用程序应针对其相应的配置服务器.我试图通过在bootstrap.properties文件中设置配置文件来实现这一点,例如:

spring.application.name=app-name
spring.cloud.config.uri=http://default-config-server.com

---
spring.profiles=dev
spring.cloud.config.uri=http://dev-config-server.com

---
spring.profiles=stage
spring.cloud.config.uri=http://stage-config-server.com

---
spring.profiles=prod
spring.cloud.config.uri=http://prod-config-server.com
Run Code Online (Sandbox Code Playgroud)

然后我设置了cla,-Dspring.profiles.active=dev但是加载的配置服务器始终是文件中设置的最后一个(即prod配置服务器将在上面的设置中加载,然后如果删除prod,则会加载stage).

是否可以为云配置服务器设置引导配置文件?我按照这个例子,但似乎无法使它工作.对于它的价值,这些配置文件非常适合加载正确的配置(即,如果dev配置文件处于活动状态,则会加载app-name-dev.properties),但不会从正确的配置服务器中提取.

java spring-profiles spring-boot spring-cloud-config

14
推荐指数
2
解决办法
1万
查看次数

How to disable Eureka and Spring Cloud Config in a WebMvcTest?

I play with a simple Spring Boot application which registers itself in Eureka and uses spring cloud configuration to read some properties.

Here it goes:

@SpringBootApplication
@EnableEurekaClient
public class Application {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

In bootstrap.yml I have:

eureka:
    client:
        serviceUrl:
            defaultZone: http://registry-service:5051/eureka/

spring:
    application:
        name: product-service
    cloud:
        config:
            discovery:
                serviceId: config-service
                enabled: true
            fail-fast: true
            retry:
                initial-interval: 2000
Run Code Online (Sandbox Code Playgroud)

I have a rest controller for which I want to write a …

spring-test spring-boot spring-cloud-netflix spring-cloud-config

13
推荐指数
2
解决办法
1万
查看次数

跨云应用程序的Spring Cloud Config Server共享属性

我目前有许多可部署的应用程序,它们以分布式方式工作,以解决业务问题.我们目前正在使用许多属性配置文件来根据系统环境变量提供每个环境的更改配置.所有这些可部署应用程序共享数据库和消息传递的通用配置 目前,这是通过从类路径中获取属性文件并使两个已部署的应用程序共享包含属性文件的每个连接(db,jms)的公共jar来实现的.

我希望尽可能开始使用Spring Config Server外部化此配置.我有一个关于如何共享此常见配置的问题.

目前它看起来像这样: -

Web1
- 数据库
- jms

Messaging1
- 数据库
- jms

在这种情况下,两个部署的应用程序共享相同的连接,并且这些连接会根据环境(lab,prf,prd等)进行更改.如何为每个可部署应用程序配备应用程序配置的Spring配置服务器实现相同目的?

Application.yml
Web1.yml Web1
-dev.yml
Messaging1.yml
Messaging1-dev.yml

如果为环境更改了连接属性,我需要对每个可部署的应用程序配置进行更改,而不是只进行一次.

目前有没有实现这一目标?我只是错过了一个简单的观点吗?

spring properties spring-cloud spring-cloud-config

12
推荐指数
3
解决办法
5350
查看次数

在 SpringBootTest 中禁用使用 spring.config.import 激活的配置服务客户端

我有一个裸露的 Spring Boot 应用程序

@SpringBootApplication
public class ClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

它通过以下内容连接到 Spring Cloud Config Serverapplication.yml

spring:
  application:
    name: client

  config:
    import: configserver:http://localhost:8888
Run Code Online (Sandbox Code Playgroud)

当配置服务器正在运行时,应用程序工作正常,而当服务器未运行时,应用程序会按预期失败。

我现在想@SpringBootTest为不依赖于正在运行的配置服务器的应用程序编写一个集成测试,甚至不尝试连接到它。

配置服务器关闭后,进行裸测试

@SpringBootTest
class ClientApplicationTests {
    @Test
    void contextLoads() {
    }
}
Run Code Online (Sandbox Code Playgroud)

失败并显示java.net.ConnectException: Connection refused,这是预期的。

当我尝试禁用配置客户端时

@SpringBootTest(properties = "spring.cloud.config.enabled=false")
Run Code Online (Sandbox Code Playgroud)

测试不会尝试连接到服务器,但失败并显示

Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:132)
    ...
Caused by: java.lang.IllegalStateException: Unable to load config data from 'configserver:http://localhost:8888'
    at …
Run Code Online (Sandbox Code Playgroud)

spring-boot spring-cloud-config spring-boot-test

12
推荐指数
2
解决办法
9033
查看次数

Spring Cloud Eureka与配置服务器

使用Eureka Server运行配置服务器时,建议的配置是什么?Config Server应该是Eureka的客户吗?或者Eureka是否应该依赖Config Server属性进行配置?或者两个都好吗?

java spring spring-cloud netflix-eureka spring-cloud-config

11
推荐指数
3
解决办法
7074
查看次数

使用JUnit Test中的远程配置启动Spring Boot上下文

我正在微服务环境中编写集成测试.我想在运行JUnit测试类时完全初始化Spring Boot应用程序上下文.在正常情况下,我可以很容易地做到这一点,但在这种情况下,我需要从Git存储库加载远程配置(我使用的是spring-cloud-config).在正常启动条件下,此Spring Boot应用程序确实从Git存储库成功加载配置.我只是试图在测试阶段复制相同的上下文初始化.以下是我编写测试类的方法:

@RunWith(SpringRunner.class)
@SpringBootTest(properties={"ENV=local","spring.cloud.config.enabled=true","spring.cloud.config.uri=http://config.server.com/config","ENCRYPT_KEY=secret"})
@ContextConfiguration(classes ={MyAppConfig.class,MyDBConfig.class})
@PropertySource({"classpath:spring-cloud-config.properties"})
public class MyIntegrationTest {

    @Test
    public void testFindUsersForCorp() {
        System.out.println("Test is running ");
    }
}
Run Code Online (Sandbox Code Playgroud)

spring-cloud-config.properties:

spring.profiles.active=${ENV}
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration
spring.cloud.consul.host=${CONSUL.HOST:localhost}
spring.cloud.consul.port=${CONSUL.PORT:8500}
spring.cloud.consul.discovery.healthCheckPath=/custom/health
spring.cloud.consul.discovery.healthCheckInterval=30s
spring.cloud.config.uri=${CONFIG.SERVER.URI:http://config.server:80/config}
spring.cloud.config.username=user
spring.cloud.config.password=${PASSWORD}
Run Code Online (Sandbox Code Playgroud)

在Spring上下文初始化期间记录输出:

main WARN: Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/userdata-service/default": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
main WARN: Cannot enhance @Configuration bean definition 'refreshScope' since its singleton instance has been created too early. The typical cause is a …
Run Code Online (Sandbox Code Playgroud)

java integration-testing junit4 spring-boot spring-cloud-config

11
推荐指数
1
解决办法
1283
查看次数

列出最终的属性列表 - Spring Cloud Config Server

当我访问应用程序的/ env端点时,Spring Cloud Config Server接受多个配置文件并返回所有配置文件的属性.响应列出了特定于每个配置文件的属性.如果2个不同的属性文件中存在相同的属性,则最后定义的属性优先.有没有办法获得应用程序将使用的属性键和值的最终列表?

spring-boot spring-cloud-netflix spring-cloud-config

11
推荐指数
2
解决办法
5484
查看次数