首页 > 解决方案 > 我对 org.springframework.mock.web 缺少什么依赖?

问题描述

我正在尝试MockMultipartFile在 Egads 的现有源代码中使用,但我不断收到此错误:package org.springframework.mock.web does not exist

这是更新的 pom 文件:

  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.yahoo.egads</groupId>
  <artifactId>egads</artifactId>

  <name>EGADS Anomaly Detection System</name>
  <description>EGADS system, consumes time series and outputs anomalies.</description>
  <version>0.4.0</version>

  <organization>
    <name>Yahoo Inc.</name>
    <url>https://www.yahoo.com/</url>
  </organization>
  <inceptionYear>2015</inceptionYear>

  <developers>
    <developer>
      <organization>Yahoo Inc.</organization>
      <organizationUrl>https://www.yahoo.com/</organizationUrl>
    </developer>
  </developers>

  <licenses>
    <license>
      <name>GPL V3</name>
      <url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
      <distribution>repo</distribution>
    </license>
  </licenses>

  <packaging>jar</packaging>

  <issueManagement>
    <system>Github</system>
    <url>https://github.com/yahoo/egads/issues</url>
  </issueManagement>

  <ciManagement>
    <system>Travis</system>
    <url>https://travis-ci.org/yahoo/egads</url>
  </ciManagement>

  <distributionManagement>
      <repository>
          <id>bintray-yahoo-egads</id>
          <name>yahoo-egads</name>
          <url>https://api.bintray.com/maven/yahoo/maven/egads;publish=1</url>
      </repository>
  </distributionManagement>
  <properties>
    <spring-boot.version>2.0.3.RELEASE</spring-boot.version>
  </properties>
  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
    </parent>

  <repositories>
    <repository>
      <id>bintray-yahoo-maven</id>
      <name>bintray</name>
      <url>http://yahoo.bintray.com/maven</url>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>bintray-yahoo-maven</id>
      <name>bintray-plugins</name>
      <url>http://yahoo.bintray.com/maven</url>
    </pluginRepository>
  </pluginRepositories>

  <dependencyManagement>
    <dependencies>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
        <version>1.7.7</version>
      </dependency>
      <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.3</version>
      </dependency>
      <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.3</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.1.1.RELEASE</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.6.RELEASE</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
      </dependency>
      <dependency>
        <groupId>com.github.lbordowitz.openforecast</groupId>
        <artifactId>openforecast</artifactId>
        <version>0.5.0</version>
      </dependency>
      <dependency>
        <groupId>jfree</groupId>
        <artifactId>jfreechart</artifactId>
        <version>1.0.13</version>
      </dependency>
      <dependency>
        <groupId>jfree</groupId>
        <artifactId>jcommon</artifactId>
        <version>1.0.16</version>
      </dependency>
      <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>19.0</version>
      </dependency>
      <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20140107</version>
      </dependency>
      <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
      </dependency>
      <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-math3</artifactId>
        <version>3.2</version>
      </dependency>

      <!-- TEST DEPENDENCIES -->
      <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>5.14.7</version>
        <scope>test</scope>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-mock</artifactId>
        <version>2.0.8</version>
        <scope>test</scope>
      </dependency>
      <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <scope>test</scope>
    </dependency>
    </dependencies>
  </dependencyManagement>

    <dependencies>
        <dependency>
         <groupId>org.slf4j</groupId>
         <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-api</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-core</artifactId>
        </dependency>

        <dependency>
          <groupId>com.github.lbordowitz.openforecast</groupId>
          <artifactId>openforecast</artifactId>
        </dependency>
        <dependency>
          <groupId>jfree</groupId>
          <artifactId>jfreechart</artifactId>
        </dependency>
        <dependency>
          <groupId>jfree</groupId>
          <artifactId>jcommon</artifactId>
        </dependency>
        <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
        </dependency>
        <dependency>
          <groupId>org.json</groupId>
          <artifactId>json</artifactId>
        </dependency>
        <dependency>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
        </dependency>
        <dependency>
          <groupId>org.apache.commons</groupId>
          <artifactId>commons-math3</artifactId>
        </dependency>

        <!-- TEST DEPENDENCIES -->
        <dependency>
          <groupId>org.testng</groupId>
          <artifactId>testng</artifactId>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
          <version>3.0.5.RELEASE</version>
        </dependency>
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-web</artifactId>
          <version>4.1.6.RELEASE</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>

          <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <classifier>exec</classifier>
            </configuration>
        </plugin>

           <plugin>
             <artifactId>maven-assembly-plugin</artifactId>
             <configuration>
               <descriptorRefs>
                 <descriptorRef>jar-with-dependencies</descriptorRef>
               </descriptorRefs>
             </configuration>
           </plugin>

           <plugin>
              <artifactId>maven-release-plugin</artifactId>
              <version>2.5.2</version>
              <dependencies>
                <dependency>
                  <groupId>org.apache.maven.scm</groupId>
                  <artifactId>maven-scm-provider-gitexe</artifactId>
                  <version>1.8.1</version>
                </dependency>
              </dependencies>
            </plugin>

            <plugin>
              <artifactId>maven-deploy-plugin</artifactId>
              <version>2.8.2</version>
              <executions>
                <execution>
                  <id>deploy</id>
                  <phase>deploy</phase>
                  <goals>
                    <goal>deploy</goal>
                  </goals>
                </execution>
              </executions>
            </plugin>

              <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.0</version>
              <configuration>
                <source>1.8</source>
                <target>1.8</target>
               </configuration>
              </plugin>
        </plugins>
    </build>
</project>

使用的最终目标MockMultiPartFile是将文件的路径从命令行参数转换为多部分文件。但我现在无法将此包添加到我的项目中。

我想知道为了在我的项目中使用这个包,我需要将哪些其他项目添加到 pom 文件中。谢谢你。

标签: javaspringspring-web

解决方案


您的 Spring Framework 依赖项一团糟。删除特定<version>标签并让spring-boot-starter-parent管理依赖项:

<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>4.1.6.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-test</artifactId>
</dependency>

您正在尝试同时使用 Spring Framework 3.X、4.X、5.X(来自 Spring Boot 2.X)组件,这些不兼容!

最有可能的 3.X 依赖项之一是降级spring-test到没有 package 的版本org.springframework.mock.web。您可以通过检查来确认这一点mvn dependency:tree


推荐阅读