Eureka和Feign MicroWebservice无法启动



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

控制器类

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);
}
}

应用程序属性文件::

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]

嗨,约根德拉, 问题出在pom上.xml事实上,我在pom中明确添加了功能区依赖项.xml虽然它已经成为eureka客户端的一部分,但由于这个,我遇到了这个问题。从 POM 中删除功能区客户端后.xml一切都很好。

相关内容

  • 没有找到相关文章

最新更新