首页 > 解决方案 > org.reflections:reflections:0.10.2 getConstructorsAnnotatedWIth 返回一个空集

问题描述

我试图从 0.9.12 更新到 0.10.2,但是当我这样做时,getConstructorsAnnotatedWith() 返回一个空集。

仅仅恢复到 0.9.12 就可以解决问题,但我想运行最新最好的版本。

我正在使用 gmavenplus 插件在编译时生成反射.xml 文件,那里没有任何改变:

<plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <version>1.6</version>
            <executions>
              <execution>
                <phase>process-classes</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <scripts>
                <script><![CDATA[
            new org.reflections.Reflections(
            "com.walterjwhite",
            org.reflections.scanners.TypeAnnotationsScanner.class,
            org.reflections.scanners.SubTypesScanner.class,
            org.reflections.scanners.FieldAnnotationsScanner.class,
            org.reflections.scanners.ResourcesScanner.class,
            org.reflections.scanners.MethodAnnotationsScanner.class
            )
            .save("${project.build.outputDirectory}/META-INF/reflections/${project.groupId}-${project.artifactId}-reflections.xml")
          ]]></script>
              </scripts>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>2.4.12</version>
                <scope>runtime</scope>
              </dependency>
              <dependency>
                <groupId>org.reflections</groupId>
                <artifactId>reflections</artifactId>
                <version>0.9.12</version>
              </dependency>
              <!-- When writing XML, this is required -->
              <dependency>
                <groupId>dom4j</groupId>
                <artifactId>dom4j</artifactId>
                <version>1.6.1</version>
              </dependency>
            </dependencies>
          </plugin>

返回空集的代码:

Reflections.collect().getConstructorsAnnotatedWith(Inject.class)

对应的依赖:

<dependencies>
    <dependency>
      <groupId>org.reflections</groupId>
      <artifactId>reflections</artifactId>
      <version>0.9.12</version>
    </dependency>
    <!-- When writing XML, this is required -->
    <dependency>
      <groupId>org.dom4j</groupId>
      <artifactId>dom4j</artifactId>
      <version>2.1.3</version>
    </dependency>
</dependencies>

标签: javareflections

解决方案


推荐阅读