简体   繁体   English

导入Spring的ReflectionTestUtils类很麻烦

[英]Trouble importing Spring's ReflectionTestUtils class

I'm working on a multi-module maven project called acme-platform , with the modules set up like so: 我正在开发一个名为acme-platform的多模块maven项目,其模块设置如下:

  1. acme-admin acme-admin
  2. acme-common 常见的
  3. acme-global acme-global
  4. acme-services acme服务
  5. acme-client 客户端
  6. acme-registration 注册
  7. acme-properties acme-properties
  8. acme-test 测验

(They are listed in this order in the acme-platform pom.) (它们在acme平台 pom中按此顺序列出。)

In some of the modules, I have been able to use Spring's ReflectionTestUtils class. 在某些模块中,我已经能够使用Spring的ReflectionTestUtils类。 However, in the last module, acme-test , where I really want to use it, I am unable to. 但是,在最后一个模块acme-test中 ,我确实要在其中使用它,但我无法使用。 There was no dependency section in the acme-test pom, so I added one. acme-test pom中没有依赖项,因此我添加了一个。 Here is the pom: 这是pom:

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> http://maven.apache.org/xsd/maven-4.0.0.xsd“>

<parent>
    <artifactId>acme-platform</artifactId>
    <groupId>com.awesomeness.acme</groupId>
    <version>1.21.0</version>
    <relativePath>../</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>acme-test</artifactId>
<version>1.21.0</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
    </dependency>
</dependencies>

Before adding the dependency lines, I couldn't import any of Spring's api into my classes. 在添加依赖项行之前,我无法将任何Spring的api导入到我的类中。 After importing these lines, I was able to access most of the classes, but not all of them, and in particular not ReflectionTestUtils, even though it is part of the spring-test module (as can be verified here ). 导入这些行之后,我可以访问大多数类,但不能访问所有类,尤其是ReflectionTestUtils,即使它是spring-test模块的一部分(可以在此处验证)。

I am using Intellij. 我正在使用Intellij。 I have looked at answers to other questions (such as this one ) to make sure I'm updating my dependencies correctly. 我已经查看了其他问题(例如这一问题)的答案,以确保我正确地更新了我的依赖关系。 To no avail. 无济于事。

Does anyone have any idea as to why I can't import org.springframework.test.util.ReflectionTestUtils into acme-test ? 有谁知道为什么我不能将org.springframework.test.util.ReflectionTestUtils导入acme-test吗?

Let me know if you need any aditional information. 让我知道您是否需要其他信息。

EDIT 编辑

The version information of the dependencies are not in any of the module poms, but they are specified in the root pom ( acme-platform ). 依赖项的版本信息不在任何模块poms中,而是在根pom( acme-platform )中指定。 Again, I can import ReflectionTest in the other modules, just not in acme-test . 同样,我可以在其他模块中导入ReflectionTest,而不能在acme-test中导入。 So I deduce from this that as long as the dependency is declared with a specified version in the root pom, it doesn't need a version specified in any of the module poms. 因此,我推断出,只要在根pom中使用指定的版本声明了依赖项,就不需要在任何模块poms中指定的版本。 (If I'm wrong on this, please correct me.) (如果我错了,请纠正我。)

ADDITIONAL EDIT 附加编辑

By the way, I can't import junit either. 顺便说一句,我也不能导入junit。


You need to set the Maven scope to test for both the spring-test and junit dependencies. 您需要设置Maven的scope ,以test两者的spring-testjunit依赖关系。

For example: 例如:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM