This commit is contained in:
Phillip Webb 2014-02-24 13:43:54 -08:00
parent 8947307702
commit cf23b519d2
25 changed files with 97 additions and 87 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -31,6 +31,8 @@ import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import org.springframework.web.servlet.handler.AbstractUrlHandlerMapping;
/**
* {@link Endpoint} to expose Spring MVC mappings.
*
* @author Dave Syer
*/
public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>>
@ -118,10 +120,10 @@ public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>
Map<String, Object> result) {
for (AbstractUrlHandlerMapping mapping : handlerMappings) {
Map<String, Object> handlers = mapping.getHandlerMap();
for (String key : handlers.keySet()) {
Object handler = handlers.get(key);
result.put(key,
Collections.singletonMap("type", handler.getClass().getName()));
for (Map.Entry<String, Object> entry : handlers.entrySet()) {
Class<? extends Object> handlerClass = entry.getValue().getClass();
result.put(entry.getKey(),
Collections.singletonMap("type", handlerClass.getName()));
}
}
}
@ -131,9 +133,11 @@ public class RequestMappingEndpoint extends AbstractEndpoint<Map<String, Object>
Map<String, Object> result) {
for (AbstractHandlerMethodMapping<?> mapping : methodMappings) {
Map<?, HandlerMethod> methods = mapping.getHandlerMethods();
for (Object key : methods.keySet()) {
result.put(key.toString(),
Collections.singletonMap("method", methods.get(key).toString()));
for (Map.Entry<?, HandlerMethod> entry : methods.entrySet()) {
result.put(
String.valueOf(entry.getKey()),
Collections.singletonMap("method",
String.valueOf(entry.getValue())));
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -29,6 +29,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Tests for {@link ShutdownMvcEndpoint}.
*
* @author Dave Syer
*/
public class ShutdownMvcEndpointTests {

View File

@ -46,12 +46,12 @@ import org.springframework.util.StringUtils;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Batch. By default a
* Runner will be created and all jobs in the context will be executed on startup.
*
* Disable this behaviour with <code>spring.batch.job.enabled=false</code>).
*
* <p>
* Disable this behavior with {@literal spring.batch.job.enabled=false}).
* <p>
* Alternatively, discrete Job names to execute on startup can be supplied by the User
* with a comma-delimited list: <code>spring.batch.job.names=job1,job2</code>. In this
* case the Runner will first find jobs registered as Beans, then those in the existing
* with a comma-delimited list: {@literal spring.batch.job.names=job1,job2}. In this case
* the Runner will first find jobs registered as Beans, then those in the existing
* JobRegistry.
*
* @author Dave Syer

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -64,7 +64,7 @@ import org.springframework.util.StringUtils;
* @author Phillip Webb
*/
@Configuration
@ConditionalOnClass(EmbeddedDatabaseType.class /* Spring JDBC */)
@ConditionalOnClass(EmbeddedDatabaseType.class)
public class DataSourceAutoConfiguration implements EnvironmentAware {
private static Log logger = LogFactory.getLog(DataSourceAutoConfiguration.class);
@ -77,26 +77,27 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
@Autowired
private ApplicationContext applicationContext;
private RelaxedPropertyResolver environment;
private RelaxedPropertyResolver datasourceProperties;
@Override
public void setEnvironment(Environment environment) {
this.environment = new RelaxedPropertyResolver(environment, CONFIGURATION_PREFIX
+ ".");
this.datasourceProperties = new RelaxedPropertyResolver(environment,
CONFIGURATION_PREFIX + ".");
}
@PostConstruct
protected void initialize() throws Exception {
if (this.dataSource == null
|| !this.environment.getProperty("initialize", Boolean.class, true)) {
boolean initialize = this.datasourceProperties.getProperty("initialize",
Boolean.class, true);
if (this.dataSource == null || !initialize) {
logger.debug("No DataSource found so not initializing");
return;
}
String schema = this.environment.getProperty("schema");
String schema = this.datasourceProperties.getProperty("schema");
if (schema == null) {
schema = "classpath*:schema-"
+ this.environment.getProperty("platform", "all")
+ this.datasourceProperties.getProperty("platform", "all")
+ ".sql,classpath*:schema.sql,classpath*:data.sql";
}
@ -106,8 +107,8 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
.getResources(schemaLocation)));
}
boolean continueOnError = this.environment.getProperty("continueOnError",
Boolean.class, false);
boolean continueOnError = this.datasourceProperties.getProperty(
"continueOnError", Boolean.class, false);
boolean exists = false;
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
for (Resource resource : resources) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -39,6 +39,7 @@ import org.springframework.core.env.Environment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert;
import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect;
import org.thymeleaf.spring4.SpringTemplateEngine;
@ -78,14 +79,13 @@ public class ThymeleafAutoConfiguration {
@PostConstruct
public void checkTemplateLocationExists() {
if (this.environment
.getProperty("checkTemplateLocation", Boolean.class, true)) {
Boolean checkTemplateLocation = this.environment.getProperty(
"checkTemplateLocation", Boolean.class, true);
if (checkTemplateLocation) {
Resource resource = this.resourceLoader.getResource(this.environment
.getProperty("prefix", DEFAULT_PREFIX));
if (!resource.exists()) {
throw new IllegalStateException("Cannot find template location: "
+ resource + " (are you really using Thymeleaf?)");
}
Assert.state(resource.exists(), "Cannot find template location: "
+ resource + " (are you really using Thymeleaf?)");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -47,6 +47,8 @@ import org.springframework.transaction.PlatformTransactionManager;
import static org.junit.Assert.assertEquals;
/**
* Tests for {@link JobLauncherCommandLineRunner}.
*
* @author Dave Syer
*/
public class JobLauncherCommandLineRunnerTests {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -27,6 +27,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Tests for {@link DispatcherServletAutoConfiguration}.
*
* @author Dave Syer
*/
public class DispatcherServletAutoConfigurationTests {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -44,6 +44,7 @@ import org.springframework.web.client.RestTemplate;
import sample.tomcat.service.HelloWorldService;
import sample.tomcat.web.SampleController;
import static org.junit.Assert.assertEquals;
/**

View File

@ -261,9 +261,9 @@ public class SpringApplication {
System.setProperty("java.awt.headless", Boolean.toString(this.headless));
Collection<SpringApplicationRunListener> participants = createRunParticipants(args);
for (SpringApplicationRunListener participant : participants) {
participant.started();
Collection<SpringApplicationRunListener> runListeners = getRunListeners(args);
for (SpringApplicationRunListener runListener : runListeners) {
runListener.started();
}
try {
@ -271,8 +271,8 @@ public class SpringApplication {
ConfigurableEnvironment environment = getOrCreateEnvironment();
addPropertySources(environment, args);
setupProfiles(environment);
for (SpringApplicationRunListener participant : participants) {
participant.environmentPrepared(environment);
for (SpringApplicationRunListener runListener : runListeners) {
runListener.environmentPrepared(environment);
}
if (this.showBanner) {
@ -287,8 +287,8 @@ public class SpringApplication {
context.setEnvironment(environment);
postProcessApplicationContext(context);
applyInitializers(context);
for (SpringApplicationRunListener participant : participants) {
participant.contextPrepared(context);
for (SpringApplicationRunListener runListener : runListeners) {
runListener.contextPrepared(context);
}
if (this.logStartupInfo) {
logStartupInfo(context.getParent() == null);
@ -298,15 +298,15 @@ public class SpringApplication {
Set<Object> sources = getSources();
Assert.notEmpty(sources, "Sources must not be empty");
load(context, sources.toArray(new Object[sources.size()]));
for (SpringApplicationRunListener participant : participants) {
participant.contextLoaded(context);
for (SpringApplicationRunListener runListener : runListeners) {
runListener.contextLoaded(context);
}
// Refresh the context
refresh(context);
afterRefresh(context, args);
for (SpringApplicationRunListener participant : participants) {
participant.finished(context, null);
for (SpringApplicationRunListener runListener : runListeners) {
runListener.finished(context, null);
}
stopWatch.stop();
@ -317,8 +317,8 @@ public class SpringApplication {
return context;
}
catch (Exception ex) {
for (SpringApplicationRunListener participant : participants) {
finishWithException(participant, context, ex);
for (SpringApplicationRunListener runListener : runListeners) {
finishWithException(runListener, context, ex);
}
if (context != null) {
context.close();
@ -330,13 +330,11 @@ public class SpringApplication {
}
}
private Collection<SpringApplicationRunListener> createRunParticipants(
String[] args) {
List<SpringApplicationRunListener> participants = new ArrayList<SpringApplicationRunListener>();
participants.addAll(getSpringFactoriesInstances(
SpringApplicationRunListener.class, new Class<?>[] {
SpringApplication.class, String[].class }, this, args));
return participants;
private Collection<SpringApplicationRunListener> getRunListeners(String[] args) {
List<SpringApplicationRunListener> listeners = new ArrayList<SpringApplicationRunListener>();
listeners.addAll(getSpringFactoriesInstances(SpringApplicationRunListener.class,
new Class<?>[] { SpringApplication.class, String[].class }, this, args));
return listeners;
}
private <T> Collection<? extends T> getSpringFactoriesInstances(Class<T> type) {
@ -625,10 +623,10 @@ public class SpringApplication {
runCommandLineRunners(context, args);
}
private void finishWithException(SpringApplicationRunListener participant,
private void finishWithException(SpringApplicationRunListener runListener,
ConfigurableApplicationContext context, Exception exception) {
try {
participant.finished(context, exception);
runListener.finished(context, exception);
}
catch (Exception ex) {
if (this.log.isDebugEnabled()) {

View File

@ -22,10 +22,10 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.support.SpringFactoriesLoader;
/**
* Strategy class to allow dynamic participation when the {@link SpringApplication}
* {@code run} method is called. Participants are loaded via the
* {@link SpringFactoriesLoader} and should declare a public constructor that accepts a
* {@link SpringApplication} instance and a {@code String[]} of arguments. A new
* Listener for the {@link SpringApplication} {@code run} method.
* {@link SpringApplicationRunListener}s are loaded via the {@link SpringFactoriesLoader}
* and should declare a public constructor that accepts a {@link SpringApplication}
* instance and a {@code String[]} of arguments. A new
* {@link SpringApplicationRunListener} instance will be created for each run.
*
* @author Phillip Webb

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.
@ -253,12 +253,12 @@ public class PropertiesConfigurationFactory<T> implements FactoryBean<T>,
if (this.target != null) {
PropertyDescriptor[] descriptors = BeanUtils
.getPropertyDescriptors(this.target.getClass());
String prefix = this.targetName != null ? this.targetName + "." : "";
String prefix = (this.targetName != null ? this.targetName + "." : "");
String[] suffixes = new String[] { ".*", "_*" };
for (PropertyDescriptor descriptor : descriptors) {
String name = descriptor.getName();
if (!name.equals("class")) {
for(String relaxedName : new RelaxedNames(prefix + name)) {
for (String relaxedName : new RelaxedNames(prefix + name)) {
names.add(relaxedName);
patterns.add(relaxedName);
for (String suffix : suffixes) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2014 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.

View File

@ -86,7 +86,7 @@ public class LoggingApplicationListenerTests {
}
@Test
public void testBaseConfigLocation() {
public void baseConfigLocation() {
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
this.logger.info("Hello world");
@ -97,7 +97,7 @@ public class LoggingApplicationListenerTests {
}
@Test
public void testOverrideConfigLocation() {
public void overrideConfigLocation() {
EnvironmentTestUtils.addEnvironment(this.context,
"logging.config: classpath:logback-nondefault.xml");
this.initializer.initialize(this.context.getEnvironment(),
@ -110,7 +110,7 @@ public class LoggingApplicationListenerTests {
}
@Test
public void testOverrideConfigDoesNotExist() throws Exception {
public void overrideConfigDoesNotExist() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"logging.config: doesnotexist.xml");
this.initializer.initialize(this.context.getEnvironment(),
@ -119,7 +119,7 @@ public class LoggingApplicationListenerTests {
}
@Test
public void testAddLogFileProperty() {
public void addLogFileProperty() {
EnvironmentTestUtils.addEnvironment(this.context,
"logging.config: classpath:logback-nondefault.xml",
"logging.file: target/foo.log");
@ -132,7 +132,7 @@ public class LoggingApplicationListenerTests {
}
@Test
public void testAddLogFilePropertyWithDefault() {
public void addLogFilePropertyWithDefault() {
assertFalse(new File("target/foo.log").exists());
EnvironmentTestUtils.addEnvironment(this.context, "logging.file: target/foo.log");
this.initializer.initialize(this.context.getEnvironment(),
@ -143,7 +143,7 @@ public class LoggingApplicationListenerTests {
}
@Test
public void testAddLogPathProperty() {
public void addLogPathProperty() {
EnvironmentTestUtils.addEnvironment(this.context,
"logging.config: classpath:logback-nondefault.xml",
"logging.path: target/foo/");