Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Eureka从自定义配置服务器加载属性_Java_Spring_Spring Boot_Netflix Eureka_Spring Cloud Netflix - Fatal编程技术网

Java 使用Eureka从自定义配置服务器加载属性

Java 使用Eureka从自定义配置服务器加载属性,java,spring,spring-boot,netflix-eureka,spring-cloud-netflix,Java,Spring,Spring Boot,Netflix Eureka,Spring Cloud Netflix,我想用一组属性引导我的web应用程序,这些属性是由在Eureka注册的服务提供的 我在本地设置了Eureka、ConfigServer(REST服务)和客户端应用程序 端口8761中公开的Eureka服务器已向其注册服务。 /data服务的端点使用一组键值对进行响应,如下所示。 配置服务器代码 @GetMapping("/data") public Map<String, String> getAllProperties(){

我想用一组属性引导我的web应用程序,这些属性是由在Eureka注册的服务提供的

我在本地设置了Eureka、ConfigServer(REST服务)和客户端应用程序

端口
8761
中公开的Eureka服务器已向其注册服务。

/data
服务的端点使用一组键值对进行响应,如下所示。

配置服务器代码

@GetMapping("/data")
    public Map<String, String> getAllProperties(){
        
        Map<String, String> dataMap = new HashMap<>();
        dataMap.put("A", "1");
        dataMap.put("B", "2");
        dataMap.put("C", "3");
        dataMap.put("D", "4");
        dataMap.put("E", "5");
        dataMap.put("F", "6");
        dataMap.put("G", "7");
        
        return dataMap;
        
    }
主类用@EnableDiscoveryClient注释,bootstrap.properties提供了以下属性

spring.cloud.config.discovery.enabled = true
spring.cloud.config.discovery.service-id = CUSTOMCONFIGSERVER
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
现在来谈谈真正的问题。如前所述,需要一个
DiscoveryClient
实例才能从Eureka中发现配置服务器实例。但当我尝试注入(@Autowire)org.springframework.cloud.client.DiscoveryClient的实例时,应用程序未能开始抱怨该类型的实例在容器中不可用

public class CustomConfigLocator implements PropertySourceLocator{
    
    @Autowired
    private DiscoveryClient discoveryClient;
org.springframework.beans.factory.unsatifiedDependencyException: 创建名为的bean时出错 'com.config.client.ConfigClientApplication.CustomConfigLocator': 通过字段“discoveryClient”表示的未满足的依赖关系; 嵌套异常是 org.springframework.beans.factory.noSuchBean定义异常:否 类型的限定bean 'org.springframework.cloud.client.discovery.DiscoveryClient' 可用:至少需要1个符合autowire条件的bean 候选人依赖项批注:

有人能建议一种从
CustomConfigLocator
类访问DiscoveryClient的方法吗

##############更新-1################


令人惊讶的是,甚至在宣布悬赏后也没有人发表评论。不知道是因为这个问题完全不合逻辑,还是因为spring根本不支持这个功能!!您可以添加项目的依赖项列表吗?@Lokesh added dependenciesHi,您可以提供您的属性中所有与Eureka和Discovery相关的属性吗?@VictorBjorn我已经在bootstrap.properties中发布了我所有的内容。如果我遗漏了什么,请告诉我。
public class CustomConfigLocator implements PropertySourceLocator{
    
    @Autowired
    private DiscoveryClient discoveryClient;
dependencies {
    implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}