Java Spring Boot项目中net.sf.saxon.FeatureKeys导入错误的解决求助
Hey there, let's get this Saxon import issue sorted out for you. The problem you're facing ties directly to changes in Saxon's package structure and class availability across versions. Here's what you can do:
1. Switch to the Updated Feature Class (For Saxon-HE 10.x+)
Starting with Saxon 10.x, the net.sf.saxon.FeatureKeys class was deprecated and replaced with a new Feature enum in a different package. If you want to stick with your current 10.6 version, update your import statement:
Replace this:
import net.sf.saxon.FeatureKeys;
With this:
import net.sf.saxon.lib.Feature;
You'll also need to adjust any references to FeatureKeys constants to use the Feature enum. For example, FeatureKeys.XSLT_VERSION becomes Feature.XSLT_VERSION.
2. Downgrade to Saxon-HE 9.x (If You Must Keep FeatureKeys)
If your code relies heavily on FeatureKeys and you don't want to refactor, downgrade your Saxon-HE dependency to a 9.x release where this class still exists. Here's the updated pom.xml entry:
<dependency> <groupId>net.sf.saxon</groupId> <artifactId>Saxon-HE</artifactId> <version>9.9.1-8</version> </dependency>
3. Verify if You Need Saxon PE/EE (Rare Case)
In some scenarios, certain constants from FeatureKeys are only available in Saxon's commercial editions (PE/EE) rather than the free HE version. If you're using such features, you'd need to switch to the appropriate commercial dependency—but this is only necessary if you've confirmed HE lacks the functionality you need.
Final Steps
After making changes to your dependencies:
- Refresh your Maven/Gradle project to pull in the updated libraries
- Clean and rebuild your Spring Boot application to clear any cached class files
内容的提问来源于stack exchange,提问作者Kakashi

