liquibase.exception.DatabaseException:java.lang.ClassNotFoundException

时间:2016-07-02 20:38:09

标签: hibernate maven liquibase jhipster

我是Liquibase和JHipster的新手,使用maven插件生成差异时遇到了一些问题。

运行mvn liquibase:diff -e -X

时出现以下错误

我的pom的相关部分是:

<plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.version}</version>
            <dependencies>
                <dependency>
                    <groupId>org.javassist</groupId>
                    <artifactId>javassist</artifactId>
                    <version>3.18.2-GA</version>
                </dependency>
                <dependency>
                    <groupId>org.liquibase.ext</groupId>
                    <artifactId>liquibase-hibernate4</artifactId>
                    <version>${liquibase-hibernate4.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-data-jpa</artifactId>
                    <version>${project.parent.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-core</artifactId>
                    <version>5.2.1.Final</version>
                </dependency>

            </dependencies>
            <configuration>
                <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                <diffChangeLogFile>
                    src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml
                </diffChangeLogFile>
                <driver>org.postgresql.Driver</driver>
                <url>jdbc:postgresql://localhost/shiftwork</url>
                <defaultSchemaName/>
                <username>postgres</username>
                <password/>
                <referenceUrl>hibernate:spring:com.teammachine.staffrostering.domain?dialect=org.hibernate.dialect.PostgreSQL94Dialect&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl>
                <verbose>true</verbose>
                <logging>debug</logging>
            </configuration>
        </plugin>
        <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
        <diffChangeLogFile>
            src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml
        </diffChangeLogFile>
        <driver>org.postgresql.Driver</driver>
        <url>jdbc:postgresql://localhost/myApp</url>
        <defaultSchemaName/>
        <username>postgres</username>
        <password/>
        <referenceUrl>hibernate:spring:com.myapp.domain?dialect=&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl>
        <verbose>true</verbose>
        <logging>debug</logging>
    </configuration>
</plugin>

也许我错了,但我的理解是缺少的类(org.hibernate.boot)是Hibernate Core的一部分,它包含在内。

  Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:166)
    ... 21 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl$Work
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:45)
    at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:57)
    at liquibase.ext.hibernate.database.HibernateSpringDatabase.buildConfigurationFromScanning(HibernateSpringDatabase.java:243)
    at liquibase.ext.hibernate.database.HibernateSpringDatabase.buildConfiguration(HibernateSpringDatabase.java:55)
    at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:45)
    at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:131)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
    at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.performLiquibaseTask(LiquibaseDatabaseDiff.java:166)
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:394)
    at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.execute(LiquibaseDatabaseDiff.java:146)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$Work
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
    ... 33 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
anton@anton-K93SV:~/git/hughestech/shiftwork/staffservice$ 

1 个答案:

答案 0 :(得分:0)

问题是您将dialect属性留在liquibase-maven-plugin配置的referenceUrl内。插件tries to look for that blank class当然失败了。 This should point实现用于Hibernate的自定义方言的类。

<referenceUrl>hibernate:spring:com.myapp.domain?dialect=&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl>
<!--                                            ^^^^^^^^ -->

如果您正在使用PostgreSQL,则取决于您的数据库版本。对于PostgreSQL 9.4或更高版本,您可以使用类org.hibernate.dialect.PostgreSQL94Dialect作为方言。

因此,请将配置更新为:

<referenceUrl>hibernate:spring:com.myapp.domain?dialect=org.hibernate.dialect.PostgreSQL94Dialect&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl>

您还依赖于插件依赖项中Hibernate的冲突版本:liquibase-hibernate4 requires Hibernate 4.3+但您依赖于Hibernate Core 5.2.1.Final和{{3} }。因此,您需要删除hibernate-core上的这种依赖关系。