【发布时间】:2018-03-15 17:48:27
【问题描述】:
我有一个用于示例项目的自定义注释处理器。我在示例项目的 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?
【问题讨论】:
-
阅读this 或者在Eclipse中将你的项目转换成maven项目。
-
这篇文章中提到的内容对我不起作用。
标签: java spring eclipse maven annotation-processing