SpringApplicationConfiguration not found: Erroneous spring-boot-starter-test content?

前端 未结 3 1828
[愿得一人]
[愿得一人] 2020-12-24 03:05

Getting a compilation error in Maven:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] --------------         


        
相关标签:
3条回答
  • 2020-12-24 03:41

    spring-boot-starter-test, like all the other Spring Boot starters, is really just a pom that pulls in a number of other dependencies transitively. It only has a jar to keep some build systems that don't like pom-only dependencies happy.

    It looks like you have upgraded an application from Spring Boot 1.4 to Spring Boot 1.5. Spring Boot 1.5 removes a number of classes that were deprecated in 1.4, including org.springframework.boot.test.SpringApplicationConfiguration.

    I would recommend dropping back to Spring Boot 1.4.4.RELEASE and fixing all of the deprecation warnings. You should then be able to upgrade to Spring Boot 1.5.1.RELEASE without difficulty.

    0 讨论(0)
  • 2020-12-24 03:43

    As the error is due to the upgrade of Spring Boot from 1.4 to 1.5, its important to note (from below) that several new classes that are introduced in 1.4 deprecated some of the existing classes leading way to finally getting removed in 1.5. The details of such can be found at: Spring boot release notes

    Quoted from website (edited):

    Additionally, Spring Boot 1.4 (and above) attempts to rationalize and simplify the various ways that a Spring Boot test can be run. You should migrate the following to use the new @SpringBootTest annotation:

    From @SpringApplicationConfiguration(classes=MyConfig.class) to @SpringBootTest(classes=MyConfig.class)

    From @ContextConfiguration(classes=MyConfig.class, loader=SpringApplicationContextLoader.class) to @SpringBootTest(classes=MyConfig.class)

    From @IntegrationTest to @SpringBootTest(webEnvironment=WebEnvironment.NONE)

    From @IntegrationTest with @WebAppConfiguration to @SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT) (or RANDOM_PORT)

    From @WebIntegrationTest to @SpringBootTest(webEnvironment=WebEnvironment.DEFINED_PORT) (or RANDOM_PORT)

    Tip Whilst migrating tests you may also want to replace any @RunWith(SpringJUnit4ClassRunner.class) declarations with Spring 4.3’s more readable @RunWith(SpringRunner.class).

    0 讨论(0)
  • 2020-12-24 03:58

    In your release the @SpringApplicationConfiguration annotation no longer exists. The new annotations are :

    @RunWith(SpringRunner.class)
    
    @SpringBootTest(classes = YourApplicationMainClass.class)
    
    @WebAppConfiguration
    
    0 讨论(0)
提交回复
热议问题