You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 ojdbc8 for Oracle 12c+, ojdbc11 for 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\#123
    
  • Explicit 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 SESSION privilege (required for basic logon).
  • If you set spring.jpa.hibernate.ddl-auto to create or update, ensure the user has schema modification rights. Try switching it to validate temporarily 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:31:26