Eureka和Feign MicroWebservice无法启动

时间:2018-06-19 13:58:06

标签: microservices netflix-eureka feign

我已经设法用一台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]

1 个答案:

答案 0 :(得分:0)

嗨Yogendra,               问题确实出在pom.xml上,我在pom.xml中显式添加了Ribbon依赖项,尽管它已经成为eureka客户端的一部分,因为这个问题。从pom.xml中删除功能区客户端后,一切都很好。