Spring Boot JDBC启动异常求助:跟随官方教程实践遇问题
Hey, let's walk through the most common pitfalls that cause startup exceptions when setting up Spring Boot with Oracle JDBC—since you mentioned you've worked through the official tutorial, set up your Eclipse project, added JDBC dependencies, handled the ojdbc14 jar, and configured application.properties but hit a snag.
First off, grab the core exception details—the Caused by section in your console stack trace is the real clue here. It’ll tell you if it’s a class loading issue, connection failure, or syntax error. With that in mind, here are the top issues to check:
1. ojdbc14 Compatibility Mismatch
ojdbc14 is a legacy driver built for JDK 1.4, but modern Spring Boot versions (2.x+, 3.x) rely on JDK 8 or newer. This version mismatch almost always causes class loading failures or connection errors.
- Fix: Swap to a driver matching your JDK: use ojdbc8 for JDK 8, ojdbc11 for JDK 17, etc.
- If you must use ojdbc14: Ensure you’re on a very old Spring Boot version (1.x) and that the jar is properly installed to your local Maven repo. Run this command to install it (adjust the version and file path to match your jar):
Double-check that yourmvn install:install-file -Dfile=ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.4.0 -Dpackaging=jarpom.xmldependency matches thegroupId,artifactId, andversionyou used in the command.
2. Incorrect application.properties Config
Oracle’s connection settings are easy to mix up with other databases. Verify these key entries:
- URL Format (SID mode):
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL - URL Format (service name mode, common for newer Oracle versions):
spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/ORCLPDB1 - Credentials: Make sure
spring.datasource.usernameandspring.datasource.passwordmatch your Oracle user’s details. - Driver Class: For ojdbc14, use
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver(newer drivers useoracle.jdbc.OracleDriver).
3. Eclipse Maven Dependency Sync Issues
Sometimes Eclipse doesn’t pick up manual jar installs or pom changes automatically:
- Right-click your project → Maven → Update Project, then check "Force Update of Snapshots/Releases".
- Verify the
ojdbc14.jarappears under your project’s Maven Dependencies folder. If not, your local repo install step failed.
4. Oracle Service Not Running
If your error is a connection timeout or "connection refused", check if Oracle’s services are up:
- Run
lsnrctl statusin your terminal to confirm the listener is running. - Open your system’s service manager (Windows Services, Linux systemd) to ensure the Oracle database instance service is active.
内容的提问来源于stack exchange,提问作者hell_storm2004

