使用 JDK 10 时找不到 javax.annotation.Resource 的 lookup() 方法

lookup() Method of javax.annotation.Resource not found when using JDK 10

我有一个 JavaEE7 应用程序,它在 Java 8 下编译得很好。现在我想迁移到 Java 10,我在内部构建 maven 时遇到问题单个 class。这是片段:

import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.inject.Inject;

import org.infinispan.Cache;

@Singleton
public class TestCacheProducer {

    @Resource(lookup="java:jboss/infinispan/testcache")
    private org.infinispan.Cache<Long, byte[]> testcache;

我正在使用以下版本将我的源编译为 java10:

根据 pom.xml

中的建议更改
<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
</dependency>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
  <configuration>
      <source>10</source>                                                
      <target>10</target>                                                
      <release>10</release>                                              
      <executable>javac10</executable>                                   
      <encoding>UTF-8</encoding>
      <compilerArgs>
         <arg>-proc:none</arg>
         <arg>--add-modules</arg>
         <arg>java.xml.bind</arg>
         <arg>--add-modules</arg>
         <arg>java.xml.ws.annotation</arg>
      </compilerArgs>
  </configuration>
  <dependencies>                                                         
    <dependency>                                                       
        <groupId>org.ow2.asm</groupId>                                 
        <artifactId>asm</artifactId>                                   
        <version>6.2</version>
    </dependency>                                                      
  </dependencies>
</plugin>

在 eclipse (photon) 中正确的接口 class 可以解决,但是当我通过 mvn install 使用 maven 时,我得到这些编译器错误。

error: cannot find symbol
            @Resource(lookup="java:jboss/infinispan/testcache")
                      ^
      symbol:   method lookup()
      location: @interface javax.annotation.Resource

我调查了这个错误,但我只发现有人使用了编译器,或者 JavaEE 版本参考(低于 JavaEE 6),其中接口 class没有 "lookup" 方法。这里不是这样

我的 Maven 版本信息 (mvn -v):

Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: C:\Softdev\maven\apache-maven-3.5.4\bin\..
Java version: 10, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-10
Default locale: de_AT, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

我还使用 mvn dependency:tree -Dverbose 来查看是否存在任何依赖关系,哪些引用了较旧的实现。有没有可能看到这个编译错误来自哪个引用文件?

提前感谢您的任何提示或帮助。

感谢您的帮助。 问题是由 maven-processor-plugin 引起的,我还必须为 JDK 10 添加编译器参数。(名为 'java.se.ee' 的模块包括所有 JEE 模块并且您不需要将它们一一包括在内)

<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>3.3.3</version>
     <executions>
        <execution>
            <id>process</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <fork>true</fork>
                <addCompileSourceRoots>true</addCompileSourceRoots>
                <compilerArguments>--add-modules=java.se.ee -J--add-modules=java.se.ee</compilerArguments>
                <outputDirectory>${project.build.directory}/metamodel</outputDirectory>
                <processors><processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                </processors>
            </configuration>
        </execution>
    </executions>
    <dependencies>  
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
    </dependencies>
</plugin>