简体   繁体   中英

JBoss - How to set default data source in multi-database environment?

I am migrating my project from JBoss EAP 6.4 to JBoss EAP 7.2.

So I am getting this kind of error,

   15:45:50,571 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "my.war")]) - failure description: {
    "WFLYCTL0412: Required services that are not installed:" => ["jboss.naming.context.java.module.DefaultDataSource"],
    "WFLYCTL0180: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.module.dummy.env.myDS is missing [jboss.naming.context.java.module..DefaultDataSource]"]
}

I got to know that this error occurs because default data source is not defined in standalone.xml . In previous versions of JBoss EAP removing DefaultDataSource was not giving this issue. In this version defining DefaultDataSource is mandatory even though those applications do not need that default data source.

So I tried giving default data source as an already existing datasource. In this kind of statement:

<default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:/jdbc/existing" /> 

And this worked fine.

Now my problem is our environment has multiple databases and their respective data sources. So we can't define a particular data source as a default. As this will interfere with our applications regular flow. And can create major issues.

We want the application to use their specific data sources only not the default one.

But JBoss EAP 7 is forcing us to specify default data source.

So we can define a dummy default data source? or is there any other alternative way?

Applicable to both JBoss EAP 7.2 and Wildfly :

Modify this part of standalone.xml to set the default datasource :

<?xml version="1.0" encoding="UTF-8"?>
<subsystem xmlns="urn:jboss:domain:datasources:3.0">
   <datasources>
      <datasource jta="true" jndi-name="java:jboss/datasources/default" pool-name="default" enabled="true" use-java-context="true" use-ccm="true" statistics-enabled="true">
         <connection-url>jdbc:mysql://localhost:3306/default?autoReconnect=true&amp;useSSL=false</connection-url>
         <driver>mysql</driver>
         <security>
            <user-name>user</user-name>
            <password>password</password>
         </security>
      </datasource>
      <drivers>
         <driver name="mysql" module="com.mysql">
            <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
         </driver>
      </drivers>
   </datasources>
</subsystem>

JBoss/Wildfly will pick up this as an default datasource.

Hope this helps you :)

standalone.xml中的默认绑定中存在默认数据源选项

default-bindings context-service="java:jboss/ee/concurrency/context/default" datasource="java:jboss/jdbc/jndi-name" managed-executor-service="java:jboss/ee/concurrency/executor/default" managed-scheduled-executor-service="java:jboss/ee/concurrency/scheduler/default" managed-thread-factory="java:jboss/ee/concurrency/factory/default"/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM