Widlfly 20: Web.xml and standalone.xml configs for datasource - wildfly

I have a ejb-based application deployed initially in jboss AS 5.0 that i'm upgrading to wildfly 20, the problem is that i cant resolve correctly the datasources defined in web.xml in the datasource section in standalone.xml
<resource-ref>
<res-ref-name>Midd2</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>jdbc/SybaseDB</mapped-name>
</resource-ref>
<resource-ref>
<res-ref-name>Midd</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>jdbc/SybaseDS2</mapped-name>
</resource-ref>
My datasources in standalone.xml
<datasource jndi-name="java:/jdbc/SybaseDB" pool-name="SybaseDB">
<connection-url>jdbc:sybase:XXXX.XXXX.XXXX.XXXX/database</connection-url>
<driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
<driver>
jconn3.jar
</driver>
<security>
<user-name>x</user-name>
<password>y</password>
</security>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>5</max-pool-size>
</pool>
</datasource>
<datasource jndi-name="java:/jdbc/SybaseDS2" pool-name="SybaseDS2">
<connection-url>jdbc:sybase:XXXX.XXXX.XXXX.XXXX/database</connection-url>
<driver-class>com.sybase.jdbc3.jdbc.SybDriver</driver-class>
<driver>
jconn3.jar
</driver>
<security>
<user-name>x</user-name>
<password>y</password>
</security>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>5</max-pool-size>
</pool>
</datasource>
But i'm getting
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.naming.context.java.module.Midd.Midd.env.Midd2 is missing [jboss.naming.context.java.module.Midd.Midd.env.jdbc.SybaseDB]",
"jboss.naming.context.java.module.Midd.Midd.env.Midd is missing [jboss.naming.context.java.module.Midd.Midd.env.jdbc.SybaseDS2]"
]
I've read a lot of docs in google but nothing that could help

Have you tried using the annotation to inject the data source?
#Resource(name = "jdbc/SybaseDB")
private DataSource dataSource1;
#Resource(name = "jdbc/SybaseDS2")
private DataSource dataSource2;
Where do you put the jconn3.jar?

Related

java.lang.ClassNotFoundException: com.mysql.jdbc.MysqlDataTruncation while deploying on wildfly

I am trying to deploy application over wildfly. Its throwing exception on run time.
standalone-full.xml
<datasources>
<datasource jndi-name="java:/TDS" pool-name="TDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://test-mysql.com:3306/abc</connection-url>
<driver>mysql</driver>
<security>
<user-name>sa</user-name>
<password>abc</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>

jta=true or xa-datasource in Jboss EAP 7

I'm trying to configure SQLSERVER datasource in standalone.xml. In my project i'm using JTA and i founded configuration with and others with . What is the difference ? I'm using this:
<datasource jta="true" jndi-name="java:jboss/datasources/mydatabase" pool-name="seguDS" enabled="true" use-java-context="true">
<connection-url>jdbc:jtds:sqlserver://192.168.40.16/mydatabase;instance=clust02</connection-url>
<driver>jtds-1.3.1.jar</driver>
<new-connection-sql>select 1</new-connection-sql>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
</pool>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
<validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
</validation>
<timeout>
<set-tx-query-timeout>true</set-tx-query-timeout>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>15</idle-timeout-minutes>
</timeout>
<statement>
<track-statements>false</track-statements>
</statement>
</datasource>
This works for me but i'm afraid if it correct or i should change to XA-DATASOURCE.
When you create a local-tx datasource in JBoss EAP 6.x or JBoss EAP 7, it defaults "jta" attribute to "true". This would help the local-tx resource to enlist in a global transaction. The "jta" attribute enables JTA integration for non-xa datasources only (https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/html-single/Administration_and_Configuration_Guide/index.html#Datasource_Parameters1).
If your application uses global transactions, i.e. it needs a transaction manager to coordinate a distributed transaction across multiple resource managers, then you need XA Datasource.

Wildfly 9 datasource spring jpa missing dependencies error on openshift

I am want to deploy an application with spring jpa using datasource from wildfly9, I think I have all configuration needed but I am getting an error.
What i have is
standalon.xml in subsystem
<datasource jndi-name="java:jboss/datasources/PostgreSQLDS"
jta="true" enabled="${postgresql.enabled}"
use-java-context="true"
pool-name="PostgreSQLDS"
use-ccm="true">
<connection-url>
jdbc:postgresql://${env.OPENSHIFT_POSTGRESQL_DB_HOST}:${env.OPENSHIFT_POSTGRESQL_DB_PORT}/${env.OPENSHIFT_APP_NAME}
</connection-url>
<driver>postgresql</driver>
<security>
<user-name>${env.OPENSHIFT_POSTGRESQL_DB_USERNAME}
</user-name>
<password>
${env.OPENSHIFT_POSTGRESQL_DB_PASSWORD}
</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<background-validation>true</background-validation>
<background-validation-millis>60000</background-validation-millis>
</validation>
<pool>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
</datasource>
<drivers>
<driver name="postgresql" module="org.postgresql.jdbc">
<xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
</driver>
</drivers>
my spring.profile.xml has
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:jboss/datasources/PostgreSQLDS"/>
</beans:bean>
and the error i am getting is
[0m[31m08:57:40,995 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "ROOT.war")]) - failure description: {"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.persistenceunit.\"ROOT.war#my-jpa\".__FIRST_PHASE__ is missing [jboss.naming.context.java.\"\\n java:comp\".env.jdbc.\"PostgreSQLDS\\n \"]",
"jboss.persistenceunit.\"ROOT.war#my-jpa\" is missing [jboss.naming.context.java.\"\\n java:comp\".env.jdbc.\"PostgreSQLDS\\n \"]"
]}
I am not sure what i am doing bad, any help is welcome
Try this JNDI resource mapping with java:comp/env and you need datasource resource reference in your app using jboss-web.xml below.
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/PostgreSQLDS"/>
</beans:bean>
Add jboss-web.xml inside WEB-INF folder with this content
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>/myAppRoot</context-root>
<resource-ref>
<res-ref-name>jdbc/PostgreSQLDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<jndi-name>java:jboss/datasources/PostgreSQLDS</jndi-name>
</resource-ref>
</jboss-web>

Environment variables in JBoss datasource

I have a JBoss server running and want to deploy a service.
The service connects to a database which is configured in the following xml file
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jta="false" jndi-name="java:/PMBootStrapDS"
pool-name="PMBootStrapDS" enabled="true" use-ccm="false">
<connection-url>jdbc:postgresql://localhost:5432/i2b2</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgresql-9.2-1002.jdbc4.jar</driver>
<security>
<user-name>i2b2pm</user-name>
<password>demouser</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
</datasources>
To deploy it on different systems easily, I want to bind the database location to an environment variable.
I tried something like this
<connection-url>jdbc:postgresql://${env.MY_DB_LOCATION}/i2b2</connection-url>
but it doesn't work.
Any suggestions on how to solve this issue?
Make sure you have property substitution enabled in your standalone.xml.
Look for the following subsytem in standalone.xml, and make sure the values are set to true
<subsystem xmlns="urn:jboss:domain:ee:1.1">
<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
<jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
</subsystem>
EDIT: This is only supported for eap6 and jboss 7.1.2 (or later)

Setting Up Mysql Connector Module in JBoss

I've got some issues with MySQL module my local JBoss.
In $JBOSS_HOME I created com/mysql/main
There, I dropped mysql-connector-java-5.1.26-bin.jar and module.xml
I then configured my datasource.
In the Netbeans project, persistence.xml was configured as attached via the Persistence Unit wizard and Netbeans automatically recognizes the configured datasource which is cool.
The issue now is that when I want to "Create Entity Classes From Database", I get this error.
I've checked all over the web. I think I have a good config but this error still persists.
Netbeans: 7.3.1; Mysql connector: 5.1.26; App Server: JBoss EAP 6.1.0; Mysql: 5.6.14; Windows 7; Java 7
Kindly advise.
Thanks.
In $JBOSS_HOME I created com/mysql/main There, I dropped mysql-connector-java-5.1.26-bin.jar and module.xml
Can you make sure the folder is under $JBOSS_HOME/modules location
I found answer today,
just set driver-class and driver the same name
com.mysql.jdbc.Driver
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>com.mysql.jdbc.Driver</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<use-strict-min>true</use-strict-min>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
And also create jboss-ds xml file and put it into -ejb\src\main\setup
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<datasource jta="false" jndi-name="java:/MysqlDS" pool-name="MysqlDS" enabled="true" use-ccm="false" statistics-enabled="false">
<connection-url>jdbc:mysql://localhost:3306/dmbs?zeroDateTimeBehavior=convertToNull&amp;useUnicode=yes&amp;characterEncoding=UTF-8</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>com.mysql.jdbc.Driver</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<use-strict-min>true</use-strict-min>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<timeout>
<set-tx-query-timeout>false</set-tx-query-timeout>
<blocking-timeout-millis>0</blocking-timeout-millis>
<idle-timeout-minutes>3</idle-timeout-minutes>
<query-timeout>0</query-timeout>
<use-try-lock>0</use-try-lock>
<allocation-retry>0</allocation-retry>
<allocation-retry-wait-millis>0</allocation-retry-wait-millis>
</timeout>
<statement>
<track-statements>true</track-statements>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
</datasources>
and my standalone.xml config
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jta="false" jndi-name="java:/MysqlDS" pool-name="MysqlDS" enabled="true" use-ccm="false" statistics-enabled="false">
<connection-url>jdbc:mysql://localhost:3306/dmbs?zeroDateTimeBehavior=convertToNull&amp;useUnicode=yes&amp;characterEncoding=UTF-8</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<driver>com.mysql.jdbc.Driver</driver>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<use-strict-min>true</use-strict-min>
<flush-strategy>IdleConnections</flush-strategy>
</pool>
<security>
<user-name>root</user-name>
<password>root</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
<timeout>
<set-tx-query-timeout>false</set-tx-query-timeout>
<blocking-timeout-millis>0</blocking-timeout-millis>
<idle-timeout-minutes>3</idle-timeout-minutes>
<query-timeout>0</query-timeout>
<use-try-lock>0</use-try-lock>
<allocation-retry>0</allocation-retry>
<allocation-retry-wait-millis>0</allocation-retry-wait-millis>
</timeout>
<statement>
<track-statements>true</track-statements>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
<drivers>
<driver name="com.mysql.jdbc.Driver" module="com.mysql.jdbc">
<driver-class>com.mysql.jdbc.Driver</driver-class>
<!-- <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>-->
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
My module.xml file in
C:\wildfly-9.0.0\modules\system\layers\base\com\mysql\jdbc\main
and near mysql driver jar
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql.jdbc">
<resources>
<resource-root path="mysql-connector-java-5.1.32-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>