How to add a service module in wildfly-swarm with .war packaging? - java

I added jdbc driver in pom.xml:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
And I add in project-defaults.yml:
swarm:
datasources:
data-sources:
erp-ds:
driver-name: sqlserver
connection-url: jdbc:sqlserver://localhost:1433;DatabaseName=COMPARTILHADO
user-name: teste
password: teste
jdbc-drivers:
sqlserver:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
xa-datasource-name: com.microsoft.sqlserver.jdbc.SQLServerXADataSource
driver-module-name: com.microsoft.sqlserver
but I run application it throws exception:
2017-06-14 13:09:54,337 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "erp-ds")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.sqlserver"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"jboss.driver-demander.java:jboss/datasources/erp-ds is missing [jboss.jdbc-driver.sqlserver]",
"org.wildfly.data-source.erp-ds is missing [jboss.jdbc-driver.sqlserver]"
]
}
In Wildfly I has to add driver in standalone.xml but I don't know in wildfly-swarm. In development stage I add a DatasourcesFraction with jdbcDriver, its easy, but when I build .war and I run uberjar java -jar ??????-swarm.jar throws exception above.

You're actually providing too much information in project-defaults.yml!
swarm:
datasources:
data-sources:
erp-ds:
driver-name: sqlserver
connection-url: jdbc:sqlserver://localhost:1433;DatabaseName=COMPARTILHADO
user-name: teste
password: teste
should be all you need.
By adding com.microsoft.sqlserver:sqljdbc4:4.0 as a project dependency, WF Swarm will automatically create the JDBC Driver configuration for you.
That may not solve the particular issue you're having, so I'd take a look at the WAR that WF Swarm modifies (the one without the .original suffix) in /target and see whether your jdbc jar is inside WEB-INF/lib.

Related

Thorntail 2.6.0.Final "WFLYJCA0114: Failed to load datasource class: com.mysql.cj.jdbc.MysqlXADataSource"

I am using Thorntail (2.6.0) for the first time and have Problems connecting it to my Mysql Database (8.0.18)
I get the following Exception
2019-12-22 17:43:08,832 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 48) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("jdbc-driver" => "mysql")
]) - failure description: "WFLYJCA0114: Failed to load datasource class: com.mysql.cj.jdbc.MysqlXADataSource"
Followed by this Exception
2019-12-22 17:43:09,981 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MainDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => ["jboss.jdbc-driver.mysql"],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.MainDS is missing [jboss.jdbc-driver.mysql]",
"jboss.driver-demander.java:jboss/datasources/MainDS is missing [jboss.jdbc-driver.mysql]"
]
}
2019-12-22 17:43:09,982 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "MainDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => [
"jboss.jdbc-driver.mysql",
"jboss.jdbc-driver.mysql"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.MainDS is missing [jboss.jdbc-driver.mysql]",
"jboss.driver-demander.java:jboss/datasources/MainDS is missing [jboss.jdbc-driver.mysql]",
"org.wildfly.data-source.MainDS is missing [jboss.jdbc-driver.mysql]"
]
}
The Following Settings I already did
I have JAVA_HOME should be Java 8 Zulu on a MacBook with Catalina
I have a module ../src/main/resources/modules/com/mysql/main/module.xml with the Following inside
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-8.0.18.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
My Persistence.xml in ../src/main/resources/META-INF/persistence.xml has this inside
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="SPU" transaction-type="JTA">
<!-- The "Java-Transaction-API" datasource here refers to the datasource defined in /src/main/resources/project-defaults.yml. -->
<jta-data-source>java:jboss/datasources/MainDS</jta-data-source>
<!-- User and password defines in project-defaults.yml -->
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.driver_class" value="com.mysql.cj.jdbc.Driver"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
and my project-defaults.yml in ../src/main/resources/project-defaults.yml has this inside
thorntail:
datasources:
jdbc-drivers:
mysql:
driver-module-name: com.mysql
driver-xa-datasource-class-name: com.mysql.cj.jdbc.MysqlXADataSource
data-sources:
MainDS:
driver-name: mysql
connection-url: jdbc:mysql://localhost:3306/Mysql
user-name: ****
password: ****
I have this in my pom:
<dependency>
<groupId>io.thorntail</groupId>
<artifactId>datasources</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${version.mysql}</version>
</dependency>
My Database is running and this should be not the problem.
I also read somewhere that there is an error in WildFly, stopping thorntail in finding com.mysql.cj.jdbc.MysqlXADataSource.
I thank everyone who tries to help me, I have this problem the whole day already.
My Goal is a Java-EE Server (FatJar) with JPA and a MySQL Database at the back.
Thorntail can autodetect many JDBC drivers, MySQL included. You don't have to create the module.xml file, and the thorntail.datasources.jdbc-drivers.mysql piece of configuration also isn't necessary. It should be enough to have a dependency on the JDBC driver (which you have), and define the datasource (which you also do). The driver-name should be mysql, which you also already have.
See https://docs.thorntail.io/2.6.0.Final/#auto-detecting-jdbc-drivers_thorntail and https://docs.thorntail.io/2.6.0.Final/#_datasources for more info.

spring boot Ojdbc6 class not found

My project settings are SpringBoot4+Mybatis+Oracle10g.This project clearly requires a ojdbc driver. So I installed Ojdbc6 into local maven repository first with the command.
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dpackaging=jar -Dversion=11.2.0.4 -Dfile=ojdbc6.jar -DgeneratePom=true
Then I import it in the pom file like this.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
Ater that,i reimported the project dependencies and found that ojdbc6.jar showed up in the external libraries. All seemed to be perfect except when I try to run codes that fetches data from Oracle, this error appeared
2018-05-01 15:57:33.709 [http-nio-8080-exec-8] ERROR org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
java.sql.SQLException: Unable to load class: oracle.jdbc.driver.OracleDriver from ClassLoader:sun.misc.Launcher$AppClassLoader#b4aac2;ClassLoader:TomcatEmbeddedWebappClassLoader
context: ROOT
delegate: true
----------> Parent Classloader:
sun.misc.Launcher$AppClassLoader#b4aac2
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:283)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
It doesn't make any sense to me.How could it not be able to load jdbc class when ojdbc.jar is clearly in the classpath?
Goto directory structure of your project where pom.xml lies and run following command
mvn spring-boot:run
if this successfully runs server then there is problem of classpath only.
Run this command mvn -U idea:idea. This command will add ojdbc jar into your IntelliJ classpath.

MongoDB DataSource Configuration In JBoss Server

How to configure MongoDB DataSource JNDI in JBoss Server.
I downloaded MongoDB jar (mongo-java-driver-3.4.2.jar) and deployed using admin console, it got successfully deployed but when I went to add Datasource in customize option I am not able to see MongoDB driver, the only one option available was h2. Why so? Do I have to do any other configuration change or am I missing any step?
I Even tried to manually create the MongoDB driver and datasource but that is also not working.
I placed module.xml and mongo-java-driver- 3.4.2.jar to the following path
..\devstudio\runtimes\jboss-eap\modules\system\layers\base\org\mongodb\main
--------- module.xml ---------------------
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.mongodb">
<resources>
<resource-root path="mongo-java-driver-3.4.2.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
--------------standalone.xml ------------
<datasource jndi-name="java:jboss/datasources/mongodb" pool-name="mongodb"
enabled="true" use-java-context="true">
<connection-url>jdbc:mongodb://127.0.0.1:27017/example;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>mongodb</driver>
</datasource>
<driver name="mongodb" module="org.mongodb">
<xa-datasource-class>mongodb.jdbc.MongoXADataSource</xa-datasource-class>
</driver>
I was getting the following error when i started the server
("subsystem" => "datasources"),
("data-source" => "mongodb")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable
dependencies" => [
"org.wildfly.data-source.mongodb is missing [jboss.jdbc-driver.mongodb]",
"jboss.driver-demander.java:jboss/datasources/mongodb is missing
[jboss.jdbc-driver.mongodb]"
]}
23:51:44,277 ERROR [org.jboss.as.controller.management-operation]
(Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "mongodb")
]) - failure description: {"WFLYCTL0180: Services with missing/unavailable
dependencies" => [
"org.wildfly.data-source.mongodb is missing [jboss.jdbc-driver.mongodb]",
"jboss.driver-demander.java:jboss/datasources/mongodb is missing
[jboss.jdbc-driver.mongodb]",
"org.wildfly.data-source.mongodb is missing [jboss.jdbc-driver.mongodb]"
]}
Could you let me know how to do JNDI Datasource configuration in JBoss Server ?? Please explain in detail as I am new for JNDI Configuration
Refer https://www.progress.com/blogs/configure-connect-for-jdbc-mongodb-driver-with-jboss-eap-64enter link description here

Use pivotal cloud foundry rabbitmq and mysql service using vcap service for spring data jpa application

I am able to use RABBITMQ and MYSQLSERVICES which is on pivotal.While binding services I am able to get the Credentials and using that credentials in my application.properties for spring data jpa project.
But this configuration that I am using is hard-coded in application.Properties To Make this configuration dynamically I came to know that we can use vcap services provided by pivotal.
So want to use run-time credentials for rabbimq and mysql.
My Code is below for reference.
File: application.propeties
rabbitmq.host=hostname
rabbitmq.virtual-host=vhost
rabbitmq.username=username
rabbitmq.password=password
rabbit.mainqueue=queue name
rabbit.errorqueue=erro queue name
spring.datasource.url=jdbc:mysql://hostname:postno
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
server.port=8000
The below is the repository file
package com.redistomysql.consumer.repo;
import org.springframework.data.jpa.repository.JpaRepository;
public interface tblemployee_personal_infoRepository extends JpaRepository<tblemployee_personal_info, Long> {
}
Any help would be appreciated.
The link for reference **http://www.java-allandsundry.com/2016/05/approaches-to-binding-spring-boot.html**
Set this configuration in application-cloud.yml for Mysql
---
spring:
datasource:
url: ${vcap.services.mydb.credentials.jdbcUrl}
username: ${vcap.services.mydb.credentials.username}
password: ${vcap.services.mydb.credentials.password}
The config for rabbitMq:
System.getEnv("VCAP_SERVICES")
The dependencies in pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-spring-service-connector</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
<!-- If you intend to deploy the app on Cloud Foundry, add the following -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cloudfoundry-connector</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-heroku-connector</artifactId>
<version>1.2.4.RELEASE</version>
</dependency>
**The manifest.yml**
---
applications:
- name: redistomysql-consumer
path: target/redistomysql-consumer-0.0.1-SNAPSHOT.jar
memory: 1024M
env:
JAVA_OPTS: -Djava.security.egd=file:/dev/./urandom
SPRING_PROFILES_ACTIVE: cloud
services:
- es-mysql-db
- es-consumer-rabbitmq-service
buildpack: https://github.com/cloudfoundry/java-buildpack.git
env:
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'

Adding a module in WildFly 8.2.0 Final release

I am new in JBoss and I try to add a jdbc driver for derby as a module in WidlFly 8.2.0.
What I did:
I added the org/apache/derby/main folder in the JBOSS_HOME/modules/system/layers/base directory
In this new folder, I added derbyclient.jar (from jdk 1.8.0_40, it contains the driver) and a new module.xml file.
The module.xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="org.apache.derby">
<resources>
<resource-root path="derbyclient.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Then, I updated the standalone.xml file as follows:
addition of this tag (in <extensions>): <extension module="org.apache.derby"/>
Declaration of my datasource and of the driver:
<datasource jndi-name="java:/DerbyDS" pool-name="DerbyDS" enabled="true" use-ccm="false">
<connection-url>jdbc:derby:MyDB;create=true</connection-url>
<driver>org.apache.derby</driver>
<security>
<user-name>demo</user-name>
<password>demo</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>
<drivers>
<driver name="org.apache.derby" module="org.apache.derby">
<xa-datasource-class>org.apache.derby.jdbc.ClientXADataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
I am getting the following error when I start WildFly:
`16:19:49,856 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "DerbyDS")
]) - failure description: {"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.data-source.java:/DerbyDS is missing [jboss.jdbc-driver.org_apache_derby]",
"jboss.driver-demander.java:/DerbyDS is missing [jboss.jdbc-driver.org_apache_derby]"
]}
16:19:49,866 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "DerbyDS")
]) - failure description: {
"JBAS014771: Services with missing/unavailable dependencies" => [
"jboss.data-source.java:/DerbyDS is missing [jboss.jdbc-driver.org_apache_derby]",
"jboss.driver-demander.java:/DerbyDS is missing [jboss.jdbc-driver.org_apache_derby]"
],
"JBAS014879: One or more services were unable to start due to one or more indirect dependencies not being available." => {
"Services that were unable to start:" => [
"jboss.data-source.reference-factory.DerbyDS",
"jboss.naming.context.java.DerbyDS"
],
"Services that may be the cause:" => ["jboss.jdbc-driver.org_apache_derby"]
}
}
16:19:49,897 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "MyApp.ear" (runtime-name : "MyApp.ear")
16:19:49,897 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "MyApp2.ear" (runtime-name : "MyApp2.ear")
16:19:49,907 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.org_apache_derby (missing) dependents: [service jboss.driver-demander.java:/DerbyDS, service jboss.data-source.java:/DerbyDS]`
Do you know what I did wrong?
Thanks in advance
I finally solved the issue by:
adding derbyclient.jar in the standalone directory (where my applications are deployed)
modifying the datasource declaration in the standalone.xml to make it reference the jar name :
<datasource jndi-name="java:/DerbyDS" pool-name="DerbyDS"enabled="true" use-ccm="false"> <connection-url>jdbc:derby:MyDB;create=true</connection-url> <driver>derbyclient.jar</driver>...
(I deleted the <drivers> tag, I don't use it anymore.)
So, I don't have errors anymore when I start WildFly. The derby driver is not declared as a module, but it will be shared among my different applications, so that's ok.
Your URL jdbc:derby://:MyDB looks invalid.

Categories