找不到SpringApplicationConfiguration:错误的spring-boot-starter-test内容?

Sim*_*zon 21 testing maven spring-boot spring-boot-test

在Maven中获取编译错误:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /C:/prototypes/demo-sse-spring-boot-master/src/test/java/com/cedric/demo/sse/SseDemoApplicationTests.java:[6,37] package org.springframework.boot.test does not exist
[ERROR] /C:/TITAN/demo-sse-spring-boot-master/src/test/java/com/cedric/demo/sse/SseDemoApplicationTests.java:[10,2] cannot find symbol
  symbol: class SpringApplicationConfiguration
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

Maven回购似乎有罐子存在:

在此输入图像描述

但是那个jar里面没有任何编译过的类.只有META-INF目录:

在此输入图像描述

这是设计的吗?我在哪里获得包含SpringApplicationConfiguration类的jar 以使Maven满意?

这是我的pom.xml的相关部分:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
        <relativePath/>
        <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>org.webjars.bower</groupId>
            <artifactId>jquery</artifactId>
            <version>2.1.3</version>
        </dependency>

        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
Run Code Online (Sandbox Code Playgroud)

小智 79

在您的版本中,@SpringApplicationConfiguration注释不再存在.新注释是:

@RunWith(SpringRunner.class)

@SpringBootTest(classes = YourApplicationMainClass.class)

@WebAppConfiguration
Run Code Online (Sandbox Code Playgroud)


And*_*son 19

spring-boot-starter-test和所有其他Spring Boot启动程序一样,它实际上只是一个可以传递许多其他依赖项的pom.它只有一个jar来保持一些不喜欢pom-only依赖项的构建系统.

您似乎已将应用程序从Spring Boot 1.4升级到Spring Boot 1.5.Spring Boot 1.5删除了许多在1.4中弃用的类,包括org.springframework.boot.test.SpringApplicationConfiguration.

我建议回到Spring Boot 1.4.4.RELEASE并修复所有弃用警告.然后,您应该能够毫无困难地升级到Spring Boot 1.5.1.RELEASE.


Van*_*gaS 18

由于错误是由于Spring Boot从1.4升级到1.5,因此需要注意的是(从下面),1.4中引入的几个新类弃用了一些现有类,最终导致在1.5中删除.有关详细信息,请参阅:Spring启动发行说明

引自网站(已编辑):

此外,Spring Boot 1.4(及更高版本)尝试合理化和简化Spring Boot测试的各种运行方式.您应该迁移以下内容以使用新的@SpringBootTest批注:

从@SpringApplicationConfiguration(classes=MyConfig.class)到@SpringBootTest(classes=MyConfig.class)

从@ContextConfiguration(classes=MyConfig.class, loader=SpringApplicationContextLoader.class)到 @SpringBootTest(classes=MyConfig.class)

从@IntegrationTest到 @SpringBootTest(webEnvironment=WebEnvironment.NONE)

从@IntegrationTest有@WebAppConfiguration到 @SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT) (or RANDOM_PORT)

从@WebIntegrationTest到 @SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT) (or RANDOM_PORT)

提示在迁移测试时,您可能还希望@RunWith(SpringJUnit4ClassRunner.class)用Spring 4.3 替换任何声明,使其 更具可读性@RunWith(SpringRunner.class).