SpringBoot4+MyBatis+Oracle10g项目Ojdbc6 Class Not Found问题求助
I've run into this exact issue a few times with Oracle JDBC drivers and Maven, so let's break down the troubleshooting steps to get this sorted:
Verify Local Maven Repository Installation
First, double-check that the ojdbc6 jar was actually installed correctly in your local Maven repo. Navigate to~/.m2/repository/com/oracle/ojdbc6/11.2.0.4/(on Windows it'sC:\Users\<your-user>\.m2\repository\com\oracle\ojdbc6\11.2.0.4\). You should see three files here:ojdbc6.jar,ojdbc6.pom, and_remote.repositories. If any of these are missing, re-run your install command with admin/root privileges (sometimes file permissions prevent Maven from writing to the repo):mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=11.2.0.4 -Dfile=ojdbc6.jar -DgeneratePom=trueCheck pom.xml Dependency Configuration
Make sure your dependency entry exactly matches the install parameters, and watch out for hidden issues:- No typos in
groupId,artifactId, orversion(they must matchcom.oracle,ojdbc6,11.2.0.4respectively) - Remove any incorrect
<scope>tags like<scope>provided</scope>— if you set this, Maven won't include the jar in your runtime classpath, which directly causes the Class Not Found error
Your dependency should look like this:
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.4</version> </dependency>- No typos in
Spring Boot Version Compatibility Check
Wait, you mentioned "SpringBoot4" — that's likely a typo (Spring Boot's latest stable as of now is 3.x). If you're using Spring Boot 3.x, it requires Java 17+, but ojdbc6 is built for Java 6. This version mismatch can cause class loading failures. Since Oracle 10g is end-of-life and won't support newer JDBC drivers, your best bet is to downgrade Spring Boot to 2.x (which supports Java 8, fully compatible with ojdbc6).Refresh Maven and Clear Caches
Maven sometimes caches stale dependency data. Run these commands to clean and refresh your project:mvn clean install -UThe
-Uflag forces Maven to update dependencies and ignore cached versions, ensuring it picks up your locally installed ojdbc6.Fix IDE Sync Issues
If you're using an IDE like IntelliJ IDEA or Eclipse, it might not have picked up the new dependency yet:- In IntelliJ: Right-click your project → Maven → Reimport All Maven Projects. You can also go to File → Invalidate Caches... → Invalidate and Restart to clear any stuck cache.
- In Eclipse: Right-click your project → Maven → Update Project. Make sure "Force Update of Snapshots/Releases" is checked before clicking OK.
Verify Driver Class and DataSource Configuration
Ensure your Spring Bootapplication.properties/application.ymlhas the correct driver class for ojdbc6:spring.datasource.driver-class-name=oracle.jdbc.OracleDriverThis class is present in ojdbc6.jar, so if the jar is properly in your classpath, this should resolve correctly.
Try a More Compatible ojdbc6 Version for Oracle 10g
The 11.2.0.4 ojdbc6 is targeted at Oracle 11g. For better compatibility with Oracle 10g, try installing the 10.2.0.5 version of ojdbc6 instead:mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=10.2.0.5 -Dfile=ojdbc6.jar -DgeneratePom=trueThen update your pom.xml dependency version to
10.2.0.5.
内容的提问来源于stack exchange,提问作者user8990480

