spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.09k stars 40.67k forks source link

@SpringApplicationConfiguration does not work in Spock test M5 #4039

Closed madorb closed 9 years ago

madorb commented 9 years ago

My Spock integration tests are no longer working after upgrading from M3 to M5.

When I run them I get the exception:

org.springframework.core.annotation.AnnotationConfigurationException: In AnnotationAttributes for annotation [org.springframework.test.context.ContextConfiguration] declared on [class com.my.package.integration.AnIntegrationTest], attribute [locations] and its alias [value] are declared with values of [{}] and [{class com.my.package.Application}], but only one declaration is permitted.

the tests look like:

@SpringApplicationConfiguration(Application.class)
@ActiveProfiles(profiles=["ci"])
@WebIntegrationTest(randomPort=true)
@Slf4j
class AnIntegrationTest extends Specification{...}

I tried it both with and without locations= and it fails the same way in either case.

In the meantime i had to revert to:

@ContextConfiguration(loader = SpringApplicationContextLoader.class, classes = Application.class)

for my tests to execute successfully

madorb commented 9 years ago

I don't know that this is specifically spock related though. This fellow mentions the same issue: http://stackoverflow.com/questions/32742344/contextconfiguration-annotation-exception/32830706#32830706

philwebb commented 9 years ago

@madorb Can you try with the latest SNAPSHOT (and make sure you are using Spring Framework 4.2.2 SNAPSHOT as well). I think you might be hitting SPR-13345 but I though that was fixed before M5 was released.

sbrannen commented 9 years ago

Please note that Spring Boot 1.3.0.M5 depends explicitly on Spring Framework 4.2.1, not 4.2.0.

The exception you are seeing was addressed in Spring Framework 4.2.1, specifically in the following issues.

And changes made to @SpringApplicationConfiguration in Spring Boot 1.3.0 M5 require Spring Framework 4.2.1. See https://github.com/spring-projects/spring-boot/issues/3635 for details.

Thus, ensuring that you are running against Spring Framework 4.2.1 should resolve your problem.

Regards,

Sam

madorb commented 9 years ago

@philwebb @sbrannen thanks for the feedback, you're correct, using Spring 4.2.1 resolves the issue

sbrannen commented 9 years ago

@madorb, you're welcome, and thanks for letting us know that 4.2.1 solves your issue!

wilkinsona commented 9 years ago

@madorb I'd recommend not specifying the version of any Spring Framework dependencies in your build.gradle or pom.xml and letting Boot's dependency management take care of it for you. It's a nice way to avoid problems like this and know that you're running on a combination of versions that's been thoroughly tested.