启动Eureka Server时出现问题

时间:2018-01-07 12:33:10

标签: java spring-boot spring-tool-suite netflix-eureka

我正在尝试使用Eureka Server和多个客户端设置Zuul网关。

到目前为止,我已经创建了Gateway和初始客户端而没有任何问题,但由于某种原因,当我尝试启动注册表时,我一直收到错误。

据我所知,问题与加载配置有关,根目录是找不到类com/sun/jersey/core/util/FeaturesAndProperties

我已经尝试明确定义Jersey组件,但无论我如何设置pom(春季进口前的运动衫,进口后的运动衫,不同版本)我都会遇到同样的问题。

我也根据这个页面http://projects.spring.io/spring-cloud/尝试了不同的版本序列,并阅读了不同的依赖项。

我也尝试过按照此处所示的指南http://www.baeldung.com/spring-cloud-netflix-eureka(我知道版本不同,我已将值调整为其他几个版本列车)

目前,在Maen依赖项部分中存在泽西导入,下面显示了pom.xml。 (见截图)

jersey files in maven dependencies

我有点困惑,为什么我不能让它运行。任何帮助将不胜感激,或指向更详细的指南。

值得一提的是我的application.yml是从我的读数中推断出来的,我得到了一个空白的application.yml(或者我已删除的application.properties)的错误

https://github.com/JoSSte/MyEurekaRegistry

的存储库

这是控制台中定义的错误行:

2018-01-07 13:05:59.334 ERROR 5708 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'jerseyFilterRegistration' defined in class path resource [org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]: Unsatisfied dependency expressed through method 'jerseyFilterRegistration' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jerseyApplication' defined in class path resource [org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.ws.rs.core.Application]: Factory method 'jerseyApplication' threw exception; nested exception is java.lang.NoClassDefFoundError: com/sun/jersey/core/util/FeaturesAndProperties

MyRegistryApplication.java

package com.example.backend;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class MyRegistryApplication {

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

application.yml

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    waitTimeInMsWhenSyncEmpty: 0

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>MyRegistry</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>MyRegistry</name>
    <description>My Gateway</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

编辑#1:

基于这个问题,How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds我决定列出我的依赖项(mvn dependency:list | grep jersey)并查看我的依赖项中是否存在与Zex冲突的版本:

[INFO]    com.sun.jersey:jersey-core:jar:1.19.1:compile
[INFO]    com.sun.jersey:jersey-server:jar:1.19.1:compile
[INFO]    com.sun.jersey:jersey-servlet:jar:1.19.1:compile
[INFO]    com.sun.jersey.contribs:jersey-apache-client4:jar:1.19.1:runtime
[INFO]    com.sun.jersey:jersey-client:jar:1.19.1:runtime

如此清单所示,我有相同版本的泽西岛。除此之外,我没有jax-rs,也没有我的依赖项中的任何玻璃鱼

2 个答案:

答案 0 :(得分:0)

阅读并发现对Tomcat类路径的大量引用,我决定尝试在不同的环境中运行代码。

我启动了一个Ubuntu虚拟机,下载了Spring Tool Suite并将the repository克隆到其中。我运行了这个项目,它没有任何麻烦。

我现在已经卸载了PC上的所有Glassfish服务器,Tomcat服务器,JDK和JRE,我正在重新安装特定的JDK并浏览我的环境变量,以确保我的类路径“干净”,期望能解决问题。

浏览我的本地Maven存储库(C:\Users\username\.m2\repository)并删除与glassfish和jersey相关的所有文件夹(关闭IDE),然后启动IDE,并运行maven update(alt + F5)诀窍。

答案 1 :(得分:0)

如果我没记错的话,必须为Spring Cloud Camden做这件事。我不知道在最近的版本中是否已修复此问题。

您可以在Eureka服务器中尝试此操作:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <requiresUnpack>
      <dependency>
        <groupId>com.netflix.eureka</groupId>
        <artifactId>eureka-core</artifactId>
      </dependency>
      <dependency>
        <groupId>com.netflix.eureka</groupId>
        <artifactId>eureka-client</artifactId>
      </dependency>
    </requiresUnpack>
  </configuration>
</plugin>