代码之家  ›  专栏  ›  技术社区  ›  ThatDataGuy

使用java回调运行Flyway迁移任务时发生ClassNotFoundException

  •  0
  • ThatDataGuy  · 技术社区  · 5 年前

    我正在尝试实现FlyWay java回调。然而,弗利似乎找不到我的课。

    [ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1 -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.flywaydb:flyway-maven-plugin:6.0.0-beta:migrate (default-cli) on project odin_build: org.flywaydb.core.api.FlywayException: Unable to instantiate class ch.x.dp.test1 : ch.x.dp.test1
    /snip.../
    Caused by: java.lang.ClassNotFoundException: ch.x.dp.test1
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass (SelfFirstStrategy.java:50)
    

    看来飞行道找不到这个班了。

    这里是我的java类:

    package ch.x.dp;
    
    import org.flywaydb.core.api.callback.Callback;
    import org.flywaydb.core.api.callback.Context;
    import org.flywaydb.core.api.callback.Event;
    
    public class test1 implements Callback {
    
        public test1() {
            System.out.println("sldhksjhdkghd");
        }
    
        public boolean supports(Event event, Context context) {
            return false;
        }
    
        public boolean canHandleInTransaction(Event event, Context context) {
            return false;
        }
    
        public void handle(Event event, Context context) {
        }
    }
    

    我的pom包含以下内容:

     <dependency>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-core</artifactId>
                <version>6.0.0-beta2</version>
            </dependency>
    

    <plugins>
                <plugin>
                    <groupId>org.flywaydb</groupId>
                    <artifactId>flyway-maven-plugin</artifactId>
                    <version>${flyway.version}</version>
                    <configuration>
                        <locations>classpath:ch.x.dp,filesystem:src/main/resources/db/migration</locations>
                        <callbacks>
                            <callback>ch.x.dp.test1</callback>
                        </callbacks>
    <snip/>
                </plugin>
    

    我已经验证了我的mvn包调用在/target中创建了一个包含test1类的jar。

    还有什么可能丢失?我怎么能知道那个飞行路线真的在用那个罐子?

    0 回复  |  直到 5 年前