Declare an XWiki Data Source in WildFly

Last modified by Eleni Cojocariu on 2026/10/29 11:09

Steps

Have WildFly open XWiki's database connections instead of XWiki opening them itself, which is the WildFly half of Use a Container-Managed Data Source. The commands below use MySQL.

  1. Register the JDBC driver of your database as a JBoss Module, so that WildFly loads it rather than the XWiki web application. For MySQL:
    WILDFLY_HOME/bin/jboss-cli.sh "embed-server, module add --name=com.mysql \
      --resources=/path/to/mysql-connector-j-x.y.z.jar \
      --dependencies=java.se,jakarta.transaction.api"

    The command writes the module descriptor itself. Take the driver JAR, at its latest version, from the page of your database.

  2. Declare the data source:
    WILDFLY_HOME/bin/jboss-cli.sh "embed-server --server-config=standalone.xml, \
      data-source add --name=XWikiDS --jndi-name=java:jboss/datasources/XWikiDS \
      --driver-name=com.mysql --connection-url=jdbc:mysql://localhost:3306/xwiki \
      --user-name=xwiki --password=xwiki \
      --transaction-isolation=TRANSACTION_READ_COMMITTED \
      --max-pool-size=50 --prepared-statements-cache-size=20 --share-prepared-statements=true"

    This writes the matching data source and driver elements into WILDFLY_HOME/standalone/configuration/standalone.xml. Should you need XA transactions, the MySQL driver class to declare is com.mysql.cj.jdbc.MysqlXADataSource.

    The last four settings are not tuning: they replace what XWiki's own pool was providing, which Use a Container-Managed Data Source explains. WildFly would otherwise apply its own defaults of 20 connections, no statement cache and whatever isolation level the driver chooses.

  3. Point Hibernate at it in WEB-INF/hibernate.cfg.xml, as Use a Container-Managed Data Source describes, with two differences that are WildFly's:
    <property name="hibernate.connection.datasource">java:jboss/datasources/XWikiDS</property>

    The name is absolute, since WildFly binds data sources under java:jboss/datasources and not under the java:comp/env that page uses for Tomcat. And hibernate.connection.provider_class goes as well, since the connection pool it names would otherwise keep opening the connections itself.

  4. Restart WildFly, then check that the connections now come from its pool:
    WILDFLY_HOME/bin/jboss-cli.sh --connect "/subsystem=datasources/data-source=XWikiDS:test-connection-in-pool"

    It answers with an outcome of success, and XWiki serves its pages as before.

FAQ

Does XWiki need a container-managed data source?

No. By default XWiki opens its own connections from WEB-INF/hibernate.cfg.xml, and the resource-ref element in WEB-INF/web.xml that would publish a data source to the web application is shipped commented out. The absolute JNDI name used above is read from WildFly's global naming context, so it resolves without that element.

Can I declare the data source by editing standalone.xml instead?

Yes, while WildFly is stopped: the elements jboss-cli.sh writes can equally be written by hand.

Related

Get Connected