You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Quarkus项目中ActiveJDBC instrumentation配置后dev模式无法识别模型

在Quarkus项目中配置ActiveJDBC Instrumentation并解决Dev模式问题

你已在pom.xml中配置ActiveJDBC instrumentation插件,手动或IDE运行时功能正常,但执行quarkus dev或mvn quarkus:dev时出现模型类不被识别的错误,报错信息如下:

org.javalite.activejdbc.InitException: you are trying to work with models, but no models are found. Maybe you have no models in project, or you did not instrument the models. It is expected that you have a file activejdbc_models.properties on classpath
at org.javalite.activejdbc.ModelFinder.getModelsForDb(ModelFinder.java:92)
at org.javalite.activejdbc.Registry.init(Registry.java:127)
at org.javalite.activejdbc.Registry.getMetaModel(Registry.java:101)
at org.javalite.activejdbc.ModelDelegate.metaModelOf(ModelDelegate.java:273)
at org.javalite.activejdbc.ModelDelegate.findAll(ModelDelegate.java:178)

该问题源于Quarkus Dev模式的增量编译机制与ActiveJDBC instrumentation执行时机不匹配,同时可能存在Lombok编译顺序、类路径资源加载的问题,以下是具体解决步骤:

1. 调整ActiveJDBC Instrumentation插件的执行阶段与配置

修改pom.xml中的插件配置,适配Quarkus编译周期,同时明确指定模型类所在包避免扫描遗漏:

<plugin>
    <groupId>org.javalite</groupId>
    <artifactId>activejdbc-instrumentation</artifactId>
    <version>3.4-j11</version>
    <executions>
        <!-- 主代码编译后执行instrumentation -->
        <execution>
            <id>main-instrument</id>
            <phase>compile</phase>
            <goals>
                <goal>instrument</goal>
            </goals>
        </execution>
        <!-- 测试代码编译后执行instrumentation -->
        <execution>
            <id>test-instrument</id>
            <phase>process-test-classes</phase>
            <goals>
                <goal>instrument</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <!-- 替换为你项目中模型类所在的包路径 -->
        <packages>com.yourproject.models</packages>
    </configuration>
</plugin>

2. 确保activejdbc_models.properties被Dev模式加载

ActiveJDBC instrumentation会在target/classes下生成activejdbc_models.properties文件,Quarkus Dev模式可能无法自动拾取该文件的增量变化,可通过以下方式解决:

  • 执行mvn clean compile后,手动将target/classes/activejdbc_models.properties复制到src/main/resources目录;
  • 或者在application.properties中添加配置,强制Dev模式加载该文件:
quarkus.classpath.include=target/classes/activejdbc_models.properties

3. 调整Lombok与ActiveJDBC的编译顺序

Lombok会在编译阶段生成字节码,ActiveJDBC需要对生成后的字节码进行instrumentation,因此要确保Lombok插件在ActiveJDBC插件之前执行,在pom.xml中按顺序配置:

<!-- 先配置Lombok插件 -->
<plugin>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-maven-plugin</artifactId>
    <version>1.18.28.0</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>delombok</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<!-- 再配置ActiveJDBC插件 -->
<plugin>
    <!-- 上述ActiveJDBC插件配置 -->
</plugin>

4. 强制Dev模式全量编译

如果增量编译导致instrumentation失效,启动Dev模式时添加强制重建参数:

mvn quarkus:dev -Dquarkus.compiler.force-rebuild=true

验证步骤

  1. 执行mvn clean compile,检查target/classes下是否生成activejdbc_models.properties,且文件中包含你的模型类;
  2. 启动quarkus dev,测试模型相关操作是否正常。

内容的提问来源于stack exchange,提问作者Sugiharto Lim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 09:51:09