簡體   English   中英

自定義注釋處理器可以在Maven中運行,但不能在Eclipse中運行

[英]Custom Annotation Processor working in Maven but not in eclipse

我有一個示例項目中使用的自定義注釋處理器。 我在示例項目的pom.xml文件中添加了以下內容

  <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <groupId>org.apache.maven.plugins</groupId>
            <configuration>
                <annotationProcessors>
                    <annotationProcessor>com.******.CustomAnnotationProcessor</annotationProcessor>
                </annotationProcessors>
                <compilerArgs>
                    <arg>-Amyarg=${project.artifactId}</arg>
                </compilerArgs>
            </configuration>
 </plugin>

然后,我在application.properties文件中聲明參數,如下所示:

@myarg@.someVal=foobar

並按如下方式訪問它:

public class TestClass {
@Value("${@myarg@.someVal}")
private String testVal;

public void testMethod(){
    System.out.println(testVal);
}
}

它在Intelli J中工作正常,因為testVal輸出為foobar。 但是,在eclipse中,出現以下錯誤:

org.springframework.beans.factory.BeanCreationException: Error creating     bean with name ‘testClass': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder ‘@myarg@.someVal’ in string value "${@myarg@.someVal}"

我知道Eclipse使用自己的編譯器,而Maven可能使用javac。 如何使此自定義注釋也適用於Eclipse?

請按照以下步驟啟用注釋處理。

  1. 右鍵單擊該項目,然后選擇“ Properties

  2. Java Compiler -> Annotation Processing 選中Enable annotation processing

在此處輸入圖片說明

  1. 打開Java Compiler -> Annotation Processing -> Factory Path 選中Enable project specific settings 將您的JAR文件添加到列表中。

在此處輸入圖片說明 4.清理並構建項目。

我也有這個問題。

99%的溶液如gyan所述。

最后1%是用於日食的,我需要“ jar”文件,需要在“工廠路徑”中指定所有需要的jar文件。

對於我的項目,這意味着

  1. 注釋定義項目jar,
  2. 注釋處理項目jar,以及
  3. javapoet.jar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM