WSO2 APIM 3.1.0:deployment.toml配置Oracle数据源被默认H2覆盖问题
Let's break down why your current setup isn't working and how to fix it properly.
The Root Cause
Looking at your generated master-datasources.xml, there are duplicate entries for both WSO2_CARBON_DB and WSO2_MB_STORE_DB—one with your Oracle config, and one with the default H2 config. This happens because:
- You didn't explicitly set the correct
jndi_nameforWSO2_MB_STORE_DB(the default usesWSO2MBStoreDB, notjdbc/WSO2_MB_STORE_DB). - Your
deployment.tomlhad redundant conflicting configurations (like overlapping[database.user]blocks and datasource definitions) that caused the config parser to append instead of overwrite default entries. - The default H2 datasource entries weren't fully overridden by your custom configs.
Step-by-Step Fix
1. Prepare Your Environment
- Stop the WSO2 APIM server if it's running.
- Backup the existing
<APIM_HOME>/repository/conf/datasources/master-datasources.xmlfile, then delete the original one (we want the server to generate a clean version from your fixeddeployment.toml). - Ensure you've placed the Oracle JDBC driver (ojdbc6.jar or ojdbc7.jar) in
<APIM_HOME>/repository/components/lib/.
2. Use the Corrected deployment.toml Configuration
Replace your current deployment.toml with the following streamlined, correct config:
[server] hostname = "localhost" node_ip = "127.0.0.1" mode = "single" base_path = "${carbon.protocol}://${carbon.host}:${carbon.management.port}" server_role = "default" [super_admin] username = "admin" password = "admin" create_admin_account = true # Configure WSO2_CARBON_DB (handles registry and user manager) [[datasource]] id = "WSO2_CARBON_DB" name = "WSO2_CARBON_DB" description = "The datasource used for registry and user manager" jndi_name = "jdbc/WSO2CarbonDB" type = "oracle" url = "jdbc:oracle:thin:@localhost:1521/xe" username = "apimuser" password = "wso2" driver = "oracle.jdbc.driver.OracleDriver" validation_query = "SELECT 1 FROM DUAL" pool_options.max_active = 100 pool_options.max_wait = 10000 pool_options.validation_interval = 10000 pool_options.test_on_borrow = true pool_options.default_auto_commit = true # Configure WSO2_MB_STORE_DB (message broker storage) [[datasource]] id = "WSO2_MB_STORE_DB" name = "WSO2_MB_STORE_DB" description = "The datasource used for message broker database" jndi_name = "WSO2MBStoreDB" type = "oracle" url = "jdbc:oracle:thin:@localhost:1521/xe" username = "apimuser" password = "wso2" driver = "oracle.jdbc.driver.OracleDriver" validation_query = "SELECT 1 FROM DUAL" pool_options.max_active = 100 pool_options.max_wait = 10000 pool_options.validation_interval = 10000 pool_options.test_on_borrow = true pool_options.default_auto_commit = false # Configure remaining required datasources [[datasource]] id = "WSO2AM_DB" name = "WSO2AM_DB" jndi_name = "jdbc/WSO2AM_DB" type = "oracle" url = "jdbc:oracle:thin:@localhost:1521/xe" username = "apimuser" password = "wso2" driver = "oracle.jdbc.driver.OracleDriver" validation_query = "SELECT 1 FROM DUAL" pool_options.max_active = 100 pool_options.max_wait = 10000 pool_options.validation_interval = 10000 [[datasource]] id = "WSO2_IDENTITY_DB" name = "WSO2_IDENTITY_DB" jndi_name = "jdbc/WSO2IdentityDB" type = "oracle" url = "jdbc:oracle:thin:@localhost:1521/xe" username = "apimuser" password = "wso2" driver = "oracle.jdbc.driver.OracleDriver" validation_query = "SELECT 1 FROM DUAL" pool_options.max_active = 80 pool_options.max_wait = 60000 pool_options.min_idle = 5 pool_options.test_on_borrow = true pool_options.validation_interval = 30000 pool_options.default_auto_commit = false [[datasource]] id = "WSO2_SHARED_DB" name = "WSO2_SHARED_DB" jndi_name = "jdbc/SHARED_DB" type = "oracle" url = "jdbc:oracle:thin:@localhost:1521/xe" username = "apimuser" password = "wso2" driver = "oracle.jdbc.driver.OracleDriver" validation_query = "SELECT 1 FROM DUAL" pool_options.max_active = 100 pool_options.max_wait = 10000 pool_options.validation_interval = 10000 [user_store] type = "database_unique_id" properties.data_source = "WSO2_CARBON_DB" properties.TenantManager = "org.wso2.carbon.user.core.tenant.JDBCTenantManager" properties.ReadGroupsPasswordHashMethod = "SHA" properties.Disabled = false properties.MaxUserNameListLength = 100 properties.MaxRoleNameListLength = 100 properties.UserRolesCacheEnabled = true properties.PasswordDigest = "SHA-256" properties.ReadGroups = true properties.ReadOnly = false properties.IsEmailUserName = false properties.DomainCalculation = "default" properties.StoreSaltedPassword = true properties.WriteGroups = true properties.UserNameUniqueAcrossTenants = false [realm_manager] data_source = "WSO2_CARBON_DB" properties.MultiTenantRealmConfigBuilder = "org.wso2.carbon.user.core.config.multitenancy.SimpleRealmConfigBuilder"
3. Verify the Setup
Start the APIM server. Once it's running, check the generated master-datasources.xml—you should see only one entry for each datasource, all pointing to your Oracle database. The server will now use Oracle for WSO2_CARBON_DB and WSO2_MB_STORE_DB instead of falling back to H2.
Key fixes in this config:
- Explicitly set
jndi_nameforWSO2_MB_STORE_DBto match the default expected JNDI name (WSO2MBStoreDB), ensuring it overrides the H2 entry. - Removed redundant config blocks (like
[database.user]) that were causing conflicts. - Linked the user store and realm manager directly to
WSO2_CARBON_DBto ensure consistency.
内容的提问来源于stack exchange,提问作者Shankar sam

