0

I'm trying to run my web application using Wildfly Swarm and .war packaging.

How should i add my jdbc driver and data source definition?

2 Answers2

0

In your project-defaults.yml

swarm:
  datasources:
    jdbc-drivers:
      crate-jdbc:
        driver-class-name: io.crate.client.jdbc.CrateDriver
        xa-datasource-class-name: org.postgresql.xa.PGXADataSource
        driver-module-name: io.crate.crate-jdbc
    data-sources:
      MyDS:
        driver-name: crate-jdbc
        connection-url: jdbc:crate://crate-service:5432/
        pool-prefill: true
        min-pool-size:  5
        max-pool-size: 10
        user-name: "dummy"
        password: "dummy"      
0

In the simple case where you can simply use the default data source in your persistence unit, you can just specify the connection details using the following Java system properties:

swarm.ds.name           - Name of the datasource (e.g. ExampleDS)   
swarm.ds.username       - Username to access the database   
swarm.ds.password       - Password to access the database   
swarm.ds.connection.url - URL connection to use

Setting these values configures the JTA data source, so you can have a very basic persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
  <persistence-unit name="example">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>entity.user</class>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create" />
      <property name="hibernate.show_sql" value="true"/>
    </properties>
  </persistence-unit>
</persistence>

The datasource name doesn't seem to matter.

For (slightly) more information, see https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/configuration_properties.html

Doctor Eval
  • 101
  • 2