0

I am trying to set up a Zuul gateway with a Eureka Server and several clients.

So far, I have created the Gateway and and initial Client without problems, but for some reason i keep getting an error when I try to start the registry.

As far as I can tell, the problem has to do with loading the configuration, with the root being that the class com/sun/jersey/core/util/FeaturesAndProperties is not found.

I have tried defining the Jersey components explicitly, but no matter how I set up the pom (jersey before the spring imports, jersey after the imports, different versions) I get the same issue.

I have also tried different release trains, based on this page http://projects.spring.io/spring-cloud/ and read up on the different dependencies.

I have also tried following the guide illustrated here http://www.baeldung.com/spring-cloud-netflix-eureka (I am aware that the version is different, I have adjusted the values to several other release trains)

At this time, the jersey imports are present in the Maen dependencies section, with the pom.xml shown below. (see screenshot)

jersey files in maven dependencies

I am a little baffled as to why i can't get this to run. any help would be appreciated, or a point to a guide with more details.

it is worth mentioning that my application.yml is deduced from my readings, and i get the same error with a blank application.yml (or application.properties, which i have deleted)

Repository at https://github.com/JoSSte/MyEurekaRegistry

This is the error line as defined in the Console:

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>

EDIT # 1:

based on this question, How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds I Decided to list my dependencies (mvn dependency:list | grep jersey) and see if there are conflicting versions of Jersey in my dependencies:

[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

As this list indicates, I have the same version of Jersey. Besides that, I have no jax-rs, nor any glassfish in my dependencies

JoSSte
  • 2,953
  • 6
  • 34
  • 54
  • I found http://tomee.apache.org/tip-jersey-client.html but I am unsure where I can define this... – JoSSte Jan 07 '18 at 16:02
  • I also tried https://howtodoinjava.com/jersey/solved-java-lang-classnotfoundexception-com-sun-jersey-spi-container-servlet-servletcontainer/ as stated in my original question ( with relevant versions ofc) – JoSSte Jan 07 '18 at 16:03

2 Answers2

0

Reading on, and discovering loads of references to Tomcat classpaths, I decided to try to run the code in a different environment.

I started up a Ubuntu Virtual machine, downloaded Spring Tool Suite and cloned the repository into that. I ran the project and it started up without any ado.

I have now uninstalled all the Glassfish servers, Tomcat servers, JDKs and JREs present on my PC and I am in the process of reinstalling a specific JDK and going through my environment variables to make sure that my classpath is "clean", which expect wil solve the issue.

Going through my local Maven repository (C:\Users\username\.m2\repository) and removing all folders relating to glassfish, and jersey (with the IDE shut down), and then startng the IDE, and running maven update (alt+F5) did the trick.

JoSSte
  • 2,953
  • 6
  • 34
  • 54
0

If I remember correctly this had to be done for Spring Cloud Camden. I don't know if this has been fixed in recent releases.

Could you try this in the Eureka server:

<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>
ootero
  • 3,235
  • 2
  • 16
  • 22
  • Thank you for your answer. I got it working without changing my pom.xml further. clearing my maven repo solved it. as i wrote in my own answer, the thing that solved it was realizing that another jersey class was in the classpath. after realizing that a vanilla installation of spring on an ubuntu which worked with the same project, without any ado. – JoSSte Jan 10 '18 at 05:30