Spring Boot应用启动抛出NoClassDefFoundError问题求助
Hey, let's tackle this NoClassDefFoundError issue you're facing with your Spring Boot + CXF-JAXRS project. I've dealt with similar dependency-related headaches before, so here's a breakdown of what's going on and how to fix it:
What's Causing This?
The error java.lang.NoClassDefFoundError: org/springframework/expression/ParserContext means the JVM can't find the ParserContext class at runtime. This class lives in the spring-expression module, so the problem is either:
- Your project is missing this dependency entirely
- There's a version conflict between Spring Boot's dependencies and those pulled in by CXF-JAXRS
Step-by-Step Fixes
1. Add the Spring Expression Dependency Explicitly
First, make sure you've got the spring-expression dependency in your pom.xml. Since you're using Spring Boot 1.5.13.RELEASE, you don't even need to specify a version—Spring Boot's parent pom will handle that for you to ensure compatibility:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> </dependency>
2. Hunt for Dependency Conflicts
If adding the dependency doesn't work, you probably have a version clash. Run this Maven command to generate a dependency tree and spot conflicting versions:
mvn dependency:tree -Dverbose
Search the output for spring-expression—you might see that a CXF-related dependency is pulling in an older or incompatible version of this module. If that's the case, exclude the conflicting version from your CXF dependency like this:
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxrs</artifactId> <version>your-cxf-version-here</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> </exclusion> </exclusions> </dependency>
3. Clean Up Your Maven Cache
Sometimes corrupted dependencies in your local Maven cache can cause weird issues. Run these commands to clean things up and re-download fresh copies:
mvn clean mvn install -U
4. Double-Check Your Spring Boot Parent Setup
Make sure your pom.xml has the correct Spring Boot parent declared—this is crucial for managing dependency versions correctly:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.13.RELEASE</version> <relativePath/> <!-- Looks up the parent from Maven repo --> </parent>
Final Checks
After making these changes, restart your STS and fire up the application again. If you still run into issues, look for other ClassNotFound errors or version mismatch warnings in the startup log—those will give you more clues to dig deeper.
内容的提问来源于stack exchange,提问作者priTHEpro

