0

I have a custom Annotation Processor which is being used in a sample project. I have added the following in the pom.xml file of the sample project

  <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>

I then declare the argument in the application.properties file as follows:

@myarg@.someVal=foobar

And access it as follows “

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

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

It is working fine in Intelli J as testVal prints out to be foobar. However, in eclipse I get the following error :

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}"

I understand that Eclipse uses its own compiler, while Maven probably uses javac. How do I get this custom annotation working for eclipse as well?

Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53
frigocat
  • 283
  • 2
  • 13
  • check this https://stackoverflow.com/questions/43404891/how-to-configure-java-annotation-processors-in-eclipse – miskender Mar 15 '18 at 17:51
  • Read [this](https://stackoverflow.com/questions/43404891/how-to-configure-java-annotation-processors-in-eclipse) Or convert your project into maven project in Eclipse. – Victor Gubin Mar 15 '18 at 17:58
  • What is mentioned in this post isn't working for me. – frigocat Mar 15 '18 at 19:22

2 Answers2

1

Please follow below steps to enable annotation processing.

  1. Right click on the project and select Properties.

  2. In Java Compiler -> Annotation Processing. Check Enable annotation processing.

enter image description here

  1. Open Java Compiler -> Annotation Processing -> Factory Path. Check Enable project specific settings. Add your JAR file to the list.

enter image description here 4. Clean and build the project.

Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53
0

I too had this problem.

99% of the solution was as gyan described.

The last 1% was for eclipse I needed "jar" files needed specify all needed jar files in the "Factory Path".

For my project this meant

  1. the annotation-definition project jar,
  2. the annotation-processing project jar, and
  3. javapoet.jar.
AndrewS
  • 413
  • 4
  • 6