Datasource Postgresql Widlfly

Asked

Viewed 293 times

1

I’m trying to set up a DataSourcewith PostgreSQL, but you’re throwing this Exception

23:36:46,381 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "meuprojeto")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.meuprojeto#meuprojeto-dev" => "java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}
23:36:46,382 ERROR [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0021: Deploy of deployment "meuprojeto.war" was rolled back with the following failure message: 
{"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.meuprojeto#meuprojeto-dev" => "java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}
23:36:46,387 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 66) WFLYJPA0011: Stopping Persistence Unit (phase 1 of 2) Service 'meuprojeto#meuprojeto-dev'
23:36:46,535 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) WFLYSRV0028: Stopped deployment meuprojeto (runtime-name: meuprojeto.war) in 152ms
[2017-10-24 11:36:46,614] Artifact meuprojeto:war exploded: Error during artifact deployment. See server log for details.
[2017-10-24 11:36:46,614] Artifact meuprojeto:war exploded: java.lang.Exception: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.meuprojeto#meuprojeto-dev" => "java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
    Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"}}

Datasource in the standalone.xml of Wildfly

<datasource jndi-name="java:jboss/datasources/meuprojetoDS" pool-name="meuprojetoDS">
    <connection-url>jdbc:postgresql://localhost:5432/meuprojetodb</connection-url>
    <connection-property name="DatabaseName">
        meuprojetodb
    </connection-property>
    <driver>org.postgresql</driver>
    <pool>
        <min-pool-size>10</min-pool-size>
        <max-pool-size>20</max-pool-size>
    </pool>
    <security>
        <user-name>postgres</user-name>
        <password>root</password>
    </security>
</datasource>
<drivers>
    <driver name="org.postgresql" module="org.postgresql">
        <xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
    </driver>
</drivers>

module.xml of the Postgresql driver

<module xmlns="urn:jboss:module:1.0" name="org.postgresql">
    <resources>
        <resource-root path="postgresql-42.1.4.jar"/>
    </resources>
    <dependencies>
          <module name="javax.api"/>
          <module name="javax.transaction.api"/>
    </dependencies>
</module>

Man persistence.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="meuprojeto-dev" transaction-type="JTA">

        <description>Dev Persistence Unit</description>

        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

        <jta-data-source>java:jboss/datasources/meuprojetoDS</jta-data-source>

        <exclude-unlisted-classes>false</exclude-unlisted-classes>

        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.transaction.flush_before_completion" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
        </properties>

    </persistence-unit>
</persistence>
  • Make sure lib org.dom4j is on your classpath. It’s probably conflicting with jboss lib.

1 answer

2


The problem is because Wildfly already has the Hibernate libs on the server itself in different versions than the application’s classpath.

By marking lib as provided in Maven you define that you will use the server library and not your local classpath Ex:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.0.7.Final</version>
    <scope>provided</scope>
</dependency>

To use the libraries that exist in your application without the provided it is necessary to configure them in MANIFEST.MF, Ex:

Manifest-Version: 1.0
...
Dependencies: org.hibernate

Vide Documentation by Widlfly

Browser other questions tagged

You are not signed in. Login or sign up in order to post.