Commit 074771ec authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '1.2.x'

parents d30dd1fa cd62596e
/* /*
* Copyright 2012-2014 the original author or authors. * Copyright 2012-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -57,6 +57,7 @@ import org.springframework.web.context.WebApplicationContext; ...@@ -57,6 +57,7 @@ import org.springframework.web.context.WebApplicationContext;
* *
* @author Dave Syer * @author Dave Syer
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson
* @see #configure(SpringApplicationBuilder) * @see #configure(SpringApplicationBuilder)
*/ */
public abstract class SpringBootServletInitializer implements WebApplicationInitializer { public abstract class SpringBootServletInitializer implements WebApplicationInitializer {
...@@ -84,6 +85,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit ...@@ -84,6 +85,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
protected WebApplicationContext createRootApplicationContext( protected WebApplicationContext createRootApplicationContext(
ServletContext servletContext) { ServletContext servletContext) {
SpringApplicationBuilder builder = createSpringApplicationBuilder(); SpringApplicationBuilder builder = createSpringApplicationBuilder();
builder.main(getClass());
ApplicationContext parent = getExistingRootWebApplicationContext(servletContext); ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);
if (parent != null) { if (parent != null) {
this.logger.info("Root context already created (using as parent)."); this.logger.info("Root context already created (using as parent).");
......
...@@ -26,6 +26,7 @@ import org.hamcrest.Matcher; ...@@ -26,6 +26,7 @@ import org.hamcrest.Matcher;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -33,12 +34,14 @@ import org.springframework.mock.web.MockServletContext; ...@@ -33,12 +34,14 @@ import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link SpringBootServletInitializerTests}. * Tests for {@link SpringBootServletInitializerTests}.
* *
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson
*/ */
public class SpringBootServletInitializerTests { public class SpringBootServletInitializerTests {
...@@ -79,6 +82,17 @@ public class SpringBootServletInitializerTests { ...@@ -79,6 +82,17 @@ public class SpringBootServletInitializerTests {
assertThat(servletInitializer.applicationBuilder.built, equalTo(true)); assertThat(servletInitializer.applicationBuilder.built, equalTo(true));
} }
@SuppressWarnings("rawtypes")
@Test
public void mainClassHasSensibleDefault() throws Exception {
new WithConfigurationAnnotation()
.createRootApplicationContext(this.servletContext);
Class mainApplicationClass = (Class<?>) new DirectFieldAccessor(this.application)
.getPropertyValue("mainApplicationClass");
assertThat(mainApplicationClass,
is(equalTo((Class) WithConfigurationAnnotation.class)));
}
private Matcher<? super Set<Object>> equalToSet(Object... items) { private Matcher<? super Set<Object>> equalToSet(Object... items) {
Set<Object> set = new LinkedHashSet<Object>(); Set<Object> set = new LinkedHashSet<Object>();
Collections.addAll(set, items); Collections.addAll(set, items);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment