2017-02-22 79 views
9

获得一个编译错误Maven中:未找到SpringApplicationConfiguration:错误的spring-boot-starter-test内容?

[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] ------------------------------------------------------------------------ 

Maven的回购似乎有罐子存在:

enter image description here

howerever那罐子内部不具有任何编译的类。只有META-INF目录:

enter image description here

是这样设计?我在哪里可以得到包含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> 

回答

11

spring-boot-starter-test,像所有其他的Spring引导初学者来说,实际上只是在一些其他依赖的传递性拉一个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。

+0

是的,这个技巧对我有用,谢谢。你能指点我一个关于这个Maven设置如何工作的全面描述,它使得它能够在不需要列出它们的情况下提取依赖关系,对于为什么1.5.1.RELEASE无法完成它,它不是很清楚,它是一个主要版本决定停止对已弃用物品的支持?再次感谢你。 –

37

在您的发布中,@SpringApplicationConfiguration注释不再存在。新的注解是:

@RunWith(SpringRunner.class) 

@SpringBootTest(classes = YourApplicationMainClass.class) 

@WebAppConfiguration 
4

由于错误是由于春季启动的从1.4升级到1.5,它的重要的(从下面)指出了在1.4中引入了一些新的类弃用一些现有的类导致最终在1.5中被删除的方式。这样的细节可以在以下网址找到:Spring boot release notes

从网站援引(编辑):

此外,弹簧引导1.4(以上)试图合理化并简化在于,弹簧引导测试能运行的各种方式。您应该迁移以下使用新@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)

提示虽然迁移的测试,你可能还需要与Spring 4.3的 更具可读性@RunWith(SpringRunner.class)更换任何 @RunWith(SpringJUnit4ClassRunner.class)声明。

+0

相应地:从@springBootTest(classes = YourApplicationMainClass.class,webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)中'@SpringBootTest(classes = YourApplicationMainClass.class)'和'@ WebIntegrationTest'从早期版本转化为单个语句' – VanagaS