Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Getting a compilation error in 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] ------------------------------------------------------------------------

Maven repo seems to have the jar present:

enter image description here

howerever that jar doesn't have any compiled classes inside it. only META-INF dir:

enter image description here

Is that by design? Where do I get the jar containing SpringApplicationConfiguration class to make Maven happy?

Here's the relevant parts of my 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>
like image 934
Simeon Leyzerzon Avatar asked Feb 22 '17 15:02

Simeon Leyzerzon


3 Answers

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

@RunWith(SpringRunner.class)

@SpringBootTest(classes = YourApplicationMainClass.class)

@WebAppConfiguration
like image 153
Mohamed Avatar answered Nov 15 '22 22:11

Mohamed


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.

like image 25
Andy Wilkinson Avatar answered Nov 16 '22 00:11

Andy Wilkinson


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).

like image 23
VanagaS Avatar answered Nov 15 '22 22:11

VanagaS