How to deploy a DataSource in jboss at application level ?

Data source definitions can be also packed in your application so that you don’t have to modify at all the server configuration. When deploying data source on WildFly as part of your application you have to add them in a specific folder, which varies depending on the application package format.

For example, for a Web application, check the kitchensink example from WildFly quickstarts:

src
├── main
│   ├── java
│   │   └── org
│   │       └── jboss
│   │           └── as
│   │               └── quickstarts
│   │                   └── kitchensink
│   │                       ├── controller
│   │                       │   └── MemberController.java
│   │                       ├── data
│   │                       │   ├── MemberListProducer.java
│   │                       │   └── MemberRepository.java
│   │                       ├── model
│   │                       │   └── Member.java
│   │                       ├── rest
│   │                       │   ├── JaxRsActivator.java
│   │                       │   └── MemberResourceRESTService.java
│   │                       ├── service
│   │                       │   └── MemberRegistration.java
│   │                       └── util
│   │                           └── Resources.java
│   ├── resources
│   │   ├── import.sql
│   │   └── META-INF
│   │       └── persistence.xml
│   └── webapp
│       ├── index.html
│       ├── index.xhtml
│       ├── resources

│       └── WEB-INF
│           ├── beans.xml
│           ├── faces-config.xml
│           ├── kitchensink-quickstart-ds.xml
│           └── templates
│               └── default.xhtml
└── test
    ├── java
    │   └── org
    │       └── jboss
    │           └── as
    │               └── quickstarts
    │                   └── kitchensink
    │                       └── test
    │                           └── MemberRegistrationIT.java
    └── resources
        ├── arquillian.xml
        ├── META-INF
        │   └── test-persistence.xml
        └── test-ds.xml

And here is the kitchensink-quickstart-ds.xml datasource:

<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
    <!-- The datasource is bound into JNDI at this location. We reference
        this in META-INF/persistence.xml -->
    <datasource jndi-name="java:jboss/datasources/KitchensinkQuickstartDS"
        pool-name="kitchensink-quickstart" enabled="true"
        use-java-context="true">
        <connection-url>jdbc:h2:mem:kitchensink-quickstart;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1</connection-url>
        <driver>h2</driver>
        <security>
            <user-name>sa</user-name>
            <password>sa</password>
        </security>
    </datasource>
</datasources>
As you can see, the format of the datasource element is the same as the one defined in the server configuration.
Please note that a Datasource deployed at application level cannot be managed using the CLI or the Web console. Therefore, it is not recommended to use deployable datasource for applications running in production.

Recommended Articles

JBoss Datasource High Availability Configuration Made Easy

Learn how to configure high availability in JBoss/ WildFly datasources, including multi-data source and Oracle RAC, with step-by-step examples.

Configure MS SQL Server Datasource on WildFly Application Server

Learn how to configure Microsoft SQLServer Datasource on WildFly application server with step-by-step instructions and examples.

Retrieve WildFly/JBoss EAP Datasources Using CLI and Programmatically - Expert Guide

Learn how to fetch WildFly/JBoss EAP datasources using CLI and programmatically. Includes JMX API examples.

Deploy WildFly Datasource XML File for Java EE Applications: A Comprehensive Guide

Learn how to deploy a WildFly datasource XML file in your Java EE application with step-by-step instructions and best practices.