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

Wildfly 11中EJB/JPA无法获取JDBC连接问题咨询(附数据源配置)

Troubleshooting JDBC Connection Issues in WildFly 11 (EJB + JPA)

Let's walk through the most likely causes and fixes for your "unable to obtain JDBC connection" problem, using the partial datasource config you provided as a starting point.

1. Fix Incomplete/Incorrect Datasource Configuration

Your provided config is truncated (<...>), so let's cover the critical gaps first:

  • Validate the Connection URL
    Your URL jdbc:oracle:thin:@*.*.*.*:1521:* uses placeholder values that need to be replaced with actual database details:

    • For Oracle SID: Use jdbc:oracle:thin:@<DB_HOST>:1521:<SID>
    • For Oracle Service Name: Use jdbc:oracle:thin:@//<DB_HOST>:1521/<SERVICE_NAME>
      Leaving the * placeholders will prevent WildFly from resolving the target database entirely.
  • Add Missing Security Credentials
    Your config doesn't include the required <security> block for database authentication. Without this, WildFly can't log into the database:

    <security>
        <user-name>your_database_username</user-name>
        <password>your_database_password</password>
    </security>
    

2. Verify Oracle Driver Deployment

WildFly 11 requires the Oracle JDBC driver to be properly configured:

  • First, confirm the <driver>oracle</driver> entry in your datasource matches the driver definition in your standalone.xml/domain.xml under the <drivers> section. It should look something like this:
    <driver name="oracle" module="com.oracle">
        <driver-class>oracle.jdbc.OracleDriver</driver-class>
        <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
    </driver>
    
  • Ensure the Oracle driver JAR is deployed as a module in WildFly (typically in jboss/modules/system/layers/base/com/oracle/main) with a valid module.xml pointing to the JAR file.

3. Tune Connection Pool Parameters & Validate Connections

Your pool settings have a few areas to check and adjust:

  • Initial vs Min Pool Size: You set <initial-pool-size>5</initial-pool-size> and <min-pool-size>10</min-pool-size>. WildFly will automatically fill the pool to min-pool-size on startup, which is fine—but make sure your database can support at least 10 concurrent connections.
  • Max Pool Size vs Database Limits: Your <max-pool-size>500</max-pool-size> is quite large. Check your Oracle database's processes and sessions parameters—if the database's maximum allowed connections are less than 500, WildFly will fail to create new connections once the limit is hit.
  • Add Connection Validation: To avoid stale connections in the pool, add validation settings to automatically detect and remove bad connections:
    <validation>
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
        <validate-on-match>true</validate-on-match>
        <background-validation>true</background-validation>
        <background-validation-millis>60000</background-validation-millis>
    </validation>
    

4. Check for Connection Leaks in EJB/JPA Code

If connections are being acquired but never released, your pool will eventually exhaust:

  • Use container-managed Entity Managers: If you're using JPA, inject the Entity Manager with @PersistenceContext instead of manually creating it—this lets WildFly handle connection cleanup automatically.
  • Enable Connection Pool Statistics: Add <statistics enabled="true"/> to your datasource config, then use the WildFly Management Console to monitor ActiveCount and AvailableCount. If ActiveCount stays at max-pool-size without decreasing, you have a connection leak.
  • Audit code for unclosed resources: Ensure any manual JDBC connections or Entity Managers are closed in finally blocks to avoid leaks.

5. Verify Network & Database Availability

Rule out basic infrastructure issues:

  • Test direct database connectivity: Use sqlplus or another client to connect to the database with the same credentials and URL from the WildFly server—if this fails, the problem is with network access, database status, or user permissions.
  • Confirm database listener is running: Ensure the Oracle TNS listener is active on port 1521, and the WildFly server can reach the database host (use ping or telnet <DB_HOST> 1521 to test).

内容的提问来源于stack exchange,提问作者user1454294

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 11:33:29