【问题标题】:Eureka and Feign MicroWebservice failing to startupEureka 和 Feign MicroWebservice 无法启动
【发布时间】:2018-06-19 13:58:05
【问题描述】:

我已经设法用一个 Eureka 服务器和两个客户端服务器构建了一个微服务,其中一个服务器正在使用 Feign 和 Ribbon 调用其他服务,并且该服务在启动后立即关闭。我试图搜索可能的问题,但我找不到任何问题。请帮我解决它。

控制器类

package com.booter.Company.controller;

import java.util.List;

import javax.websocket.server.PathParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.booter.Company.dto.CompanyDTO;
import com.booter.Company.dto.EmployeeDTO;

@RestController
@RequestMapping("/company")
public class CompanyController {

    private Logger log = LoggerFactory.getLogger(CompanyController.class);

    @Autowired
    private CompanyControllerProxy proxy;


    @RequestMapping(path= {"/{name}"}, method= {RequestMethod.GET})
    public CompanyDTO companyDetails(@PathParam("from") String name) {
        CompanyDTO dto = new CompanyDTO();
        dto.setName(name);
        dto.setAffiliatedTo("HCL Group Of Companies..");

        List<EmployeeDTO> employees = proxy.returnEmployeeList();
        log.info("{}",employees);
        dto.setEmployees(employees);

        return dto;

    }
}

假装代理类调用其他服务

    package com.booter.Company.controller;

    import java.util.List;

    import org.springframework.cloud.netflix.ribbon.RibbonClient;
    import org.springframework.cloud.openfeign.FeignClient;
    import org.springframework.web.bind.annotation.GetMapping;

    import com.booter.Company.dto.EmployeeDTO;

    @FeignClient(name="person-service")
    @RibbonClient(name="person-service")
    public interface CompanyControllerProxy {

        @GetMapping("/api/persons")
        public List<EmployeeDTO> returnEmployeeList();
    }

引导类

    package com.booter.Company;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
    import org.springframework.cloud.openfeign.EnableFeignClients;

    @SpringBootApplication
    @EnableFeignClients("com.booter.Company.controller")
    @EnableDiscoveryClient
    public class CompanyApplication {

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

application.properties 文件::

    spring.application.name = company-service
    server.port = 8200
    eureka.client.serviceUrl.defaultZone=http://localhost:8005/eureka

日志

   org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:184) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:52) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:157) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:121) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:885) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
at com.booter.Company.CompanyApplication.main(CompanyApplication.java:15) [classes/:na]

【问题讨论】:

  • 添加错误日志:
  • 嗨 Sud,请检查您的 pom.xml 并在此处分享您使用的 spring-boot 和 spring-cloud 版本。

标签: microservices netflix-eureka feign


【解决方案1】:

你好约根德拉, 问题确实出在 pom.xml 上,我在 pom.xml 中明确添加了功能区依赖项,而它已经是 eureka 客户端的一部分,因此我遇到了这个问题。从 pom.xml 中删除功能区客户端后一切正常。

【讨论】:

    猜你喜欢
    • 2020-11-02
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    • 2017-01-01
    • 2019-01-08
    • 1970-01-01
    • 2016-03-21
    • 2015-07-20
    相关资源
    最近更新 更多