Spring MVC环境下Maven依赖Oracle JDBC驱动找不到问题求助
Hey there, let's work through this frustrating JDBC driver problem you're hitting. The root cause here is almost certainly that Oracle's JDBC drivers aren't hosted in the public Maven Central Repository—Oracle restricts distribution of these jars, so plain pom.xml dependencies won't download automatically. Let's break down the fixes step by step:
1. Install the Oracle JDBC Driver to Your Local Maven Repository Properly
Just copying the jar into your ./m2 folder won't cut it—Maven needs metadata (like a pom.xml file) to recognize the dependency. Use the Maven install:install-file command to properly register the jar:
First, download the correct JDBC driver for your Oracle XE version:
- Oracle XE 11g → use
ojdbc6.jar(version ~11.2.0.4) - Oracle XE 18c/21c → use
ojdbc8.jar(version ~12.2.0.1 or higher)
Then run this command in your terminal (replace the placeholders with your actual file path and version):
mvn install:install-file -Dfile=/path/to/your/ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
This will place the jar and auto-generate the necessary metadata in your local ./m2 repository.
2. Add the Correct Dependency to Your pom.xml
Once the driver is installed locally, add this dependency to your project's pom.xml (match the groupId, artifactId, and version to what you used in the install command):
<dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc8</artifactId> <version>12.2.0.1</version> </dependency>
For Spring Boot, you can also optionally use the spring-boot-starter-jdbc or spring-boot-starter-data-jpa starters alongside this to simplify database setup.
3. Verify Your Spring Boot Database Configuration
Double-check your application.properties (or application.yml) for correct connection details:
# Oracle XE connection string spring.datasource.url=jdbc:oracle:thin:@localhost:1521:XE # Correct driver class spring.datasource.driver-class-name=oracle.jdbc.OracleDriver # Your Oracle username/password spring.datasource.username=your_db_username spring.datasource.password=your_db_password
Make sure the port 1521 and service name XE match your Oracle XE setup—sometimes XE uses ORCL as the service name instead, so adjust if needed.
4. Fix STS Maven Repository Configuration
Ensure STS is pointing to your local ./m2 repository:
- Open STS and go to
Window > Preferences > Maven > User Settings - Confirm the
User Settingspath points to yoursettings.xml(usually in~/.m2/settings.xml) - Click
Update Settingsand thenReindexto refresh Maven's cache
5. Clean and Rebuild Your Project
Finally, clear any cached build artifacts and rebuild:
- In STS: Right-click your project →
Maven > Clean, thenMaven > Install - Or via command line:
mvn clean install
This should resolve the "driver not found" error by ensuring Maven properly recognizes and loads the Oracle JDBC driver.
内容的提问来源于stack exchange,提问作者Bshwajeet

