启动Eureka Server遇com.sun.jersey类缺失问题求助
com.sun.jersey.core.util.FeaturesAndProperties Hey there, let's tackle this Eureka Server startup issue you're facing. The missing com.sun.jersey.core.util.FeaturesAndProperties class is a common problem tied to dependency conflicts between Eureka's required Jersey 1.x and newer Spring Boot/Jersey versions. Here's how to resolve it step by step:
1. Explicitly Add Required Jersey 1.x Dependencies
Eureka Server relies on Jersey 1.x for its internal REST communication, but sometimes transitive dependencies get excluded or overridden. Add these explicit dependencies to your pom.xml to ensure the missing class is present:
<dependencies> <!-- Eureka Server core starter --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <!-- Explicit Jersey 1.x dependencies to resolve the missing class --> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> <version>1.19.1</version> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-server</artifactId> <version>1.19.1</version> </dependency> <dependency> <groupId>com.sun.jersey.contribs</groupId> <artifactId>jersey-apache-client4</artifactId> <version>1.19.1</version> </dependency> </dependencies>
2. Exclude Conflicting Jersey 2.x Dependencies
If your project is pulling in Jersey 2.x (from other Spring starters, for example), it will clash with Jersey 1.x. Run mvn dependency:tree to check for org.glassfish.jersey or javax.ws.rs-api entries, then exclude them from the Eureka Server starter:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> <exclusions> <exclusion> <groupId>org.glassfish.jersey</groupId> <artifactId>jersey-client</artifactId> </exclusion> <exclusion> <groupId>org.glassfish.jersey</groupId> <artifactId>jersey-core</artifactId> </exclusion> <exclusion> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> </exclusion> </exclusions> </dependency>
3. Confirm Spring Boot & Spring Cloud Version Compatibility
Mismatched versions between Spring Boot and Spring Cloud are a frequent culprit here. Ensure your release trains align:
- For Spring Boot 2.7.x, use Spring Cloud 2021.0.x (Kilburn)
- For Spring Boot 2.6.x, use Spring Cloud 2021.0.x or 2020.0.x (Ilford)
Double-check official compatibility guidelines to avoid version-related dependency conflicts.
4. Clean and Rebuild Your Project
After adjusting dependencies, clear cached artifacts and rebuild to ensure all changes take effect:
mvn clean install -U
The -U flag forces Maven to update snapshot dependencies, guaranteeing you're using the correct versions.
Why This Happens
Eureka Server is built on Jersey 1.x, but newer Spring Boot versions may default to Jersey 2.x (which uses org.glassfish.jersey packages instead of com.sun.jersey). When the required Jersey 1.x core module is missing or replaced, Eureka can't load the FeaturesAndProperties class—even with an empty application.yml, since the issue is in the classpath, not your configuration.
内容的提问来源于stack exchange,提问作者JoSSte

