如果 class 是从 jar 加载的,则无法获取自定义注释

cannot fetch custom annotations if class is loaded from jar

我在我的 WebProject 中为我的一个模型 class 添加了自定义 java 注释。现在的问题是,如果我将 class 保留在我的项目 war 的引用模块 jar 中,我将无法获取模型 class 中添加的字段级自定义注释。如果 class 作为同一个项目 war 的一部分保存,我从那里获取所有 annotations.I 甚至将保留策略标记为 "RUNTIME" 但它没有帮助.任何想法,这里有什么问题。

public class SalesUploadData {

    @ExcelColumn(position = 0)
    private Integer countryCode;
    @ExcelColumn(position = 1)
    private Integer currencyCode;
    @ExcelColumn(position = 2)
    private String serialNumber;

    public Integer getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(Integer countryCode) {
        this.countryCode = countryCode;
    }
}

@Documented
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = ElementType.FIELD)
public @interface ExcelColumn {
    String name() default "";
    int position();
    String dateFormat() default "";
    boolean isMandatory() default false;
}

我正在服务器中部署两个 WAR,如下图所示。

正如评论中提到的那样,解决方案是将 <attachClasses>true</attachClasses> 添加到 maven-war-plugin 以生成一个仅包含 类 中 Web 模块的附加工件 module-classes.jar 存档以用作其他模块的依赖项。