Ошибка подключения службы ограничения к серверу конфигурации Spring Cloud - PullRequest
0 голосов
/ 29 апреля 2020

Я хотел бы попросить вашей помощи относительно вышеуказанного вопроса. Теперь я пытаюсь связать приложение (SpringCloudConfigServer) с другим приложением (Limits-service), приложение Limits-service должно выбрать файл свойств SpringCloudConfigServer. когда я нажимаю http://localhost: 8080 / пределы мне нужно получить выходной сигнал, как {"максимум": 888, "минимум": 8}, но я получаю {"максимум": 999, "минимум": 99 }

это моя трассировка стека

2020-04-29 22:51:23.740  INFO 2016 --- [  restartedMain] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at :` http://localhost:8888
2020-04-29 22:51:25.063  INFO 2016 --- [  restartedMain] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-04-29 22:51:25.074  WARN 2016 --- [  restartedMain] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/limits-service/dev": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
2020-04-29 22:51:25.074  INFO 2016 --- [  restartedMain] c.i.m.l.LimitsServiceApplication         : The following profiles are active: dev
2020-04-29 22:51:27.792  INFO 2016 --- [  restartedMain] o.s.cloud.context.scope.GenericScope     : BeanFactory id=fe72d2a0-4692-3641-b317-8a12c5b9eb59
2020-04-29 22:51:29.065  INFO 2016 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-04-29 22:51:29.099  INFO 2016 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-04-29 22:51:29.099  INFO 2016 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-04-29 22:51:29.349  INFO 2016 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-04-29 22:51:29.349  INFO 2016 --- [  restartedMain] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 4166 ms
2020-04-29 22:51:30.477  INFO 2016 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-29 22:51:31.571  INFO 2016 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2020-04-29 22:51:31.941  INFO 2016 --- [  restartedMain] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2020-04-29 22:51:32.269  INFO 2016 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-04-29 22:51:32.627  INFO 2016 --- [  restartedMain] c.i.m.l.LimitsServiceApplication         : Started LimitsServiceApplication in 12.155 seconds (JVM running for 14.055)
2020-04-29 22:51:39.114  INFO 2016 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-04-29 22:51:39.115  INFO 2016 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-04-29 22:51:39.151  INFO 2016 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 35 ms

вот мой код обслуживания пределов

package com.in28minutes.microservices.limitsservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class LimitsServiceApplication {



public static void main(String[] args) {
        SpringApplication.run(LimitsServiceApplication.class, args);
    }

}

`controller

package com.in28minutes.microservices.limitsservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.in28minutes.microservices.limitsservice.bean.LimitConfiguration;

@RestController
public class LimitsConfigurationController {
    @Autowired
    private Configuration configuration;
    @GetMapping("/limits")
    public LimitConfiguration retrieveLimitsFromConfigurations() {
        return new LimitConfiguration(configuration.getMaximum(), 

configuration.getMinimum());

        }

    }

класс компонентов

package com.in28minutes.microservices.limitsservice;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties("limits-service")
public class Configuration {
    private int minimum;
    private int maximum;
    public int getMinimum() {
        return minimum;
    }
    public int getMaximum() {
        return maximum;
    }
    public void setMinimum(int minimum) {
        this.minimum = minimum;
    }
    public void setMaximum(int maximum) {
        this.maximum = maximum;
    }



}

Класс EJB

package com.in28minutes.microservices.limitsservice.bean;

public class LimitConfiguration {
    private int maximum;
    private int minimum;

    protected LimitConfiguration() {

    }

    public LimitConfiguration(int maximum, int minimum) {
        super();
        this.maximum = maximum;
        this.minimum = minimum;
    }

    public int getMaximum() {
        return maximum;
    }

    public int getMinimum() {
        return minimum;
    }   

}

bootstrap .properties

spring.application.name=limits-service

spring.cloud.config.server.uri=http://localhost:8888

/ git -localconfig-repo / limit-service.properties

limits-service.minimum=8
limits-service.maximum=888

помогите пожалуйста как это исправить

1 Ответ

0 голосов
/ 02 мая 2020

Похоже, ваш вызов сервера конфигурации не удается. Вот почему вы не можете загрузить свойства с сервера конфигурации, но из локального файла конфигурации вашего сервиса

Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/limits-service/dev": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect 2020-04-29 22:51:25.074 INFO 2016 --- [ restartedMain] c.i.m.l.LimitsServiceApplication : The following profiles are active: dev

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...