I have a Spock test case where I want to load a Spring application. I have a very rudimentary Groovy class that is my config object:
@Configuration
@EnableAutoConfiguration
class TestConfig {
@Bean
Map createSillyMsgMap() {
["sillyMsg" : "This is a silly message"]
}
public static void main(String[] args) {
println "TestConfig.main(${args})"
}
}
Obviously, this is isn't very useful, but it serves as an example. For convenience, I've also added the main method in that class. My test class just tries to instantiate this as a Spring Boot Application. Something like this:
class AppContextSpec extends Specification {
def "testSpringApplication"() {
given: "a Spring Configuration"
SpringApplication app = new SpringApplication(TestConfig)
app.headless = true
app.webEnvironment = false
app.applicationContextClass = AnnotationConfigApplicationContext
expect: "the Spring Application to be able to start"
ConfigurableApplicationContext ctxt = app.run((String[]) ["blah"])
}
}
I'm trying to force Spring Boot to NOT use the EmbeddedWebApplicationContext by explicitly setting the webEnvironment property to false. But no matter what I do, Spring Boot insists on starting a Tomcat server, and it does seem to pull in other resources in the source tree that are marked with @Component and/or @Configuration. There are several other application contexts on the classpath, and certainly jar files that imply web service kind of stuff, but I'm very surprised that what's on the classpath should take precedence over explicit configuration through the webEnvironment property. I'm using Gradle 1.12 as the build system, and the Spring Boot version is 1.1.4, and I'm using Groovy 2.3.6 with Spock 0.7-groovy-2.0. Any help with this is appreciated.
Am I doing something completely out of the norm here? Thanks.