Refactor to work with Spring 4.0

Refactor code to work with Spring 4.0 M1
pull/1/merge
Phillip Webb 12 years ago
parent a8d6b435a4
commit a0fb085102

@ -18,7 +18,6 @@ package org.springframework.bootstrap.autoconfigure.jdbc;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -32,7 +31,6 @@ import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.task.AsyncUtils;
import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
@ -57,8 +55,6 @@ public class EmbeddedDatabaseAutoConfiguration {
"org.hsqldb.Database"); "org.hsqldb.Database");
} }
private ExecutorService executorService;
// FIXME: DB platform // FIXME: DB platform
@Value("${spring.jdbc.schema:classpath*:schema.sql}") @Value("${spring.jdbc.schema:classpath*:schema.sql}")
private Resource[] schemaLocations = new Resource[0]; private Resource[] schemaLocations = new Resource[0];
@ -83,7 +79,7 @@ public class EmbeddedDatabaseAutoConfiguration {
public DataSource dataSource() { public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder() EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
.setType(getEmbeddedDatabaseType()); .setType(getEmbeddedDatabaseType());
return AsyncUtils.submitVia(this.executorService, builder).build(); return builder.build();
} }
public static EmbeddedDatabaseType getEmbeddedDatabaseType() { public static EmbeddedDatabaseType getEmbeddedDatabaseType() {

@ -27,7 +27,6 @@ import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.ServletContextInitializer;
/** /**
* Abstract base class for {@link EmbeddedServletContainerFactory} implementations. * Abstract base class for {@link EmbeddedServletContainerFactory} implementations.

@ -18,7 +18,6 @@ package org.springframework.bootstrap.context.embedded;
import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.bootstrap.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.web.ServletContextInitializer;
/** /**
* Factory interface that can be used to create {@link EmbeddedServletContainer}s. * Factory interface that can be used to create {@link EmbeddedServletContainer}s.

@ -40,7 +40,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextException; import org.springframework.context.ApplicationContextException;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.web.ServletContextInitializer;
import org.springframework.web.context.ContextLoader; import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.ServletContextAware;
@ -48,7 +47,6 @@ import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.GenericWebApplicationContext; import org.springframework.web.context.support.GenericWebApplicationContext;
import org.springframework.web.context.support.ServletContextAwareProcessor; import org.springframework.web.context.support.ServletContextAwareProcessor;
import org.springframework.web.context.support.ServletContextResource; import org.springframework.web.context.support.ServletContextResource;
import org.springframework.web.context.support.WebApplicationContextServletContextAwareProcessor;
import org.springframework.web.context.support.WebApplicationContextUtils; import org.springframework.web.context.support.WebApplicationContextUtils;
/** /**

@ -29,7 +29,6 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.ServletContextInitializer;
/** /**
* A {@link ServletContextInitializer} to register {@link Filter}s in a Servlet 3.0+ * A {@link ServletContextInitializer} to register {@link Filter}s in a Servlet 3.0+

@ -23,7 +23,6 @@ import javax.servlet.Registration;
import org.springframework.core.Conventions; import org.springframework.core.Conventions;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.ServletContextInitializer;
/** /**
* Base class for {@link ServletRegistrationBean servlet} and * Base class for {@link ServletRegistrationBean servlet} and

@ -0,0 +1,53 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.bootstrap.context.embedded;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.springframework.web.SpringServletContainerInitializer;
import org.springframework.web.WebApplicationInitializer;
/**
* Interface used to configure a Servlet 3.0+ {@link ServletContext context}
* programmatically. Unlike {@link WebApplicationInitializer}, classes that implement this
* interface (and do not implement {@link WebApplicationInitializer}) will <b>not</b> be
* detected by {@link SpringServletContainerInitializer} and hence will not be
* automatically bootstrapped by the Servlet container.
*
* <p>
* This interface is primarily designed to allow {@link ServletContextInitializer}s to be
* managed by Spring and not the Servlet container.
*
* <p>
* For configuration examples see {@link WebApplicationInitializer}.
*
* @author Phillip Webb
* @see WebApplicationInitializer
*/
public interface ServletContextInitializer {
/**
* Configure the given {@link ServletContext} with any servlets, filters, listeners
* context-params and attributes necessary for initialization.
* @param servletContext the {@code ServletContext} to initialize
* @throws ServletException if any call against the given {@code ServletContext}
* throws a {@code ServletException}
*/
void onStartup(ServletContext servletContext) throws ServletException;
}

@ -28,7 +28,6 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRegistration; import javax.servlet.ServletRegistration;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.ServletContextInitializer;
/** /**
* A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+ * A {@link ServletContextInitializer} to register {@link Servlet}s in a Servlet 3.0+

@ -0,0 +1,56 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.bootstrap.context.embedded;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import org.springframework.util.Assert;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.support.ServletContextAwareProcessor;
/**
* Variant of {@link ServletContextAwareProcessor} for use with a
* {@link ConfigurableWebApplicationContext}. Can be used when registering the processor
* can occur before the {@link ServletContext} or {@link ServletConfig} have been
* initialized.
*
* @author Phillip Webb
*/
public class WebApplicationContextServletContextAwareProcessor extends
ServletContextAwareProcessor {
private final ConfigurableWebApplicationContext webApplicationContext;
public WebApplicationContextServletContextAwareProcessor(
ConfigurableWebApplicationContext webApplicationContext) {
Assert.notNull(webApplicationContext, "WebApplicationContext must not be null");
this.webApplicationContext = webApplicationContext;
}
@Override
protected ServletContext getServletContext() {
ServletContext servletContext = this.webApplicationContext.getServletContext();
return (servletContext != null ? servletContext : super.getServletContext());
}
@Override
protected ServletConfig getServletConfig() {
ServletConfig servletConfig = this.webApplicationContext.getServletConfig();
return (servletConfig != null ? servletConfig : super.getServletConfig());
}
}

@ -37,12 +37,12 @@ import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer;
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.bootstrap.context.embedded.EmptyEmbeddedServletContainer; import org.springframework.bootstrap.context.embedded.EmptyEmbeddedServletContainer;
import org.springframework.bootstrap.context.embedded.ErrorPage; import org.springframework.bootstrap.context.embedded.ErrorPage;
import org.springframework.bootstrap.context.embedded.ServletContextInitializer;
import org.springframework.context.ResourceLoaderAware; import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.ServletContextInitializer;
/** /**
* {@link EmbeddedServletContainerFactory} that can be used to create * {@link EmbeddedServletContainerFactory} that can be used to create

@ -23,8 +23,8 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.webapp.AbstractConfiguration; import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration; import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
import org.springframework.bootstrap.context.embedded.ServletContextInitializer;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.ServletContextInitializer;
/** /**
* Jetty {@link Configuration} that calls {@link ServletContextInitializer}s. * Jetty {@link Configuration} that calls {@link ServletContextInitializer}s.

@ -22,8 +22,8 @@ import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener; import org.apache.catalina.LifecycleListener;
import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardContext;
import org.springframework.bootstrap.context.embedded.ServletContextInitializer;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.ServletContextInitializer;
/** /**
* Tomcat {@link LifecycleListener} that calls {@link ServletContextInitializer}s. * Tomcat {@link LifecycleListener} that calls {@link ServletContextInitializer}s.

@ -43,11 +43,11 @@ import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerEx
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.bootstrap.context.embedded.EmptyEmbeddedServletContainer; import org.springframework.bootstrap.context.embedded.EmptyEmbeddedServletContainer;
import org.springframework.bootstrap.context.embedded.ErrorPage; import org.springframework.bootstrap.context.embedded.ErrorPage;
import org.springframework.bootstrap.context.embedded.ServletContextInitializer;
import org.springframework.context.ResourceLoaderAware; import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.web.ServletContextInitializer;
/** /**
* {@link EmbeddedServletContainerFactory} that can be used to create * {@link EmbeddedServletContainerFactory} that can be used to create

@ -44,7 +44,6 @@ import org.springframework.http.client.ClientHttpResponse;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.ServletContextInitializer;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;

@ -37,7 +37,6 @@ import org.springframework.context.ApplicationContextException;
import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.web.ServletContextInitializer;
import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.ServletContextAware;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.SessionScope; import org.springframework.web.context.request.SessionScope;

@ -38,7 +38,6 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainer;
import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory; import org.springframework.bootstrap.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.web.ServletContextInitializer;
/** /**
* Mock {@link EmbeddedServletContainerFactory}. * Mock {@link EmbeddedServletContainerFactory}.

Loading…
Cancel
Save