Spring Boot启动报错:Oracle数据库登录被拒问题咨询
Hey there! Let's tackle this Logon denied issue you're facing with Spring Boot and Oracle. Since your same datasource works fine with plain Hibernate, the problem is likely in how Spring Boot handles the connection setup. Here are the most common fixes to try:
1. Check Oracle Driver Compatibility
Spring Boot manages dependency versions via its parent pom, so the Oracle JDBC driver version might not match your Oracle database version. For example, using an older driver like ojdbc6 with Oracle 19c can cause authentication hiccups.
- Stick to the driver version recommended for your Oracle release: use
ojdbc8for Oracle 12c+,ojdbc11for 21c+. - Explicitly specify the driver version in your build file to override Spring Boot's default if needed:
<!-- Maven example --> <dependency> <groupId>com.oracle.database.jdbc</groupId> <artifactId>ojdbc8</artifactId> <version>19.3.0.0</version> </dependency>
2. Verify Application Properties Configuration
Double-check your application.properties for subtle differences compared to your working Hibernate setup—small typos or format mismatches often cause this issue:
JDBC URL Format: Spring Boot expects the modern thin driver URL format. If your Hibernate setup used the old SID-based format, switch to the service name variant:
spring.datasource.url=jdbc:oracle:thin:@//<your-host>:<port>/<service-name>(Note the
//before the host—this is mandatory for newer Oracle driver versions.)Username/Password: Ensure no trailing spaces, and escape special characters (like
#,$) in your password:spring.datasource.password=MySecurePass\#123Explicit Driver Class: Avoid auto-detection issues by setting the driver class directly:
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
3. Adjust Datasource Pool Settings
Spring Boot uses HikariCP as the default connection pool, which has different default behaviors than other pools you might have used with plain Hibernate. Try tweaking these Hikari-specific properties:
spring.datasource.hikari.connection-test-query=SELECT 1 FROM DUAL spring.datasource.hikari.maximum-pool-size=5 spring.datasource.hikari.connection-timeout=30000
The connection-test-query ensures connections are valid before use, which fixes authentication errors caused by stale pool connections.
4. Rule Out Devtools Interference
Devtools' hot-reload mechanism can sometimes mess up datasource initialization. Try disabling it temporarily to test:
spring.devtools.restart.enabled=false
Or comment out the Devtools dependency in your build file and restart the app.
5. Validate Database User Permissions
Even if Hibernate works, Spring Boot might attempt extra operations (like schema validation) that your user lacks permissions for:
- Confirm your database user has the
CREATE SESSIONprivilege (required for basic logon). - If you set
spring.jpa.hibernate.ddl-autotocreateorupdate, ensure the user has schema modification rights. Try switching it tovalidatetemporarily to rule out permission issues:spring.jpa.hibernate.ddl-auto=validate
If none of these fix the problem, share the full stack trace of the Logon denied error—it’ll help pinpoint exact causes like wrong authentication protocols or missing SSL wallet files.
内容的提问来源于stack exchange,提问作者abhishek chauhan

