Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip Webb committed Feb 24, 2014
1 parent 8947307 commit cf23b51
Show file tree
Hide file tree
Showing 25 changed files with 97 additions and 87 deletions.
6 changes: 3 additions & 3 deletions docs/howto.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ database is in a server.
JPA has features for DDL generation, and these can be set up to
run on startup against the database. This is controlled through two
external properties:
external properties:
* `spring.jpa.generate-ddl` (boolean) switches the feature on and off
and is vendor independent
Expand Down Expand Up @@ -902,7 +902,7 @@ enables it by default and loads SQL from the standard locations
addition Spring Boot will load a file `schema-${platform}.sql` where
`platform` is the vendor name of the database (`hsqldb`, `h2,
`oracle`, `mysql`, `postgresql` etc.). Spring Boot enables the
failfast feature of the Spring JDBC initializer by default, so if
failfast feature of the Spring JDBC initializer by default, so if
the scripts cause exceptions the application will fail.

To disable the failfast you can set
Expand Down Expand Up @@ -945,7 +945,7 @@ startup (see
[JobLauncherCommandLineRunner](https://github.com/spring-projects/spring-boot/blob/master/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JobLauncherCommandLineRunner.java)
for details). You can narrow down to a specific job or jobs by
specifying `spring.batch.job.names` (comma separated job name
patterns).
patterns).
If the application context includes a `JobRegistry` then
the jobs in `spring.batch.job.names` are looked up in the regsitry
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -31,6 +31,8 @@
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>>
Expand Down Expand Up @@ -118,10 +120,10 @@ protected void extractHandlerMappings(
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()));
}
}
}
Expand All @@ -131,9 +133,11 @@ protected void extractMethodMappings(
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())));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -29,6 +29,8 @@
import static org.mockito.Mockito.when;

/**
* Tests for {@link ShutdownMvcEndpoint}.
*
* @author Dave Syer
*/
public class ShutdownMvcEndpointTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@
/**
* {@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
* @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);
Expand All @@ -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";
}

Expand All @@ -106,8 +107,8 @@ protected void initialize() throws Exception {
.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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -78,14 +79,13 @@ public void setEnvironment(Environment environment) {

@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?)");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -47,6 +47,8 @@
import static org.junit.Assert.assertEquals;

/**
* Tests for {@link JobLauncherCommandLineRunner}.
*
* @author Dave Syer
*/
public class JobLauncherCommandLineRunnerTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -27,6 +27,8 @@
import static org.junit.Assert.assertNotNull;

/**
* Tests for {@link DispatcherServletAutoConfiguration}.
*
* @author Dave Syer
*/
public class DispatcherServletAutoConfigurationTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -44,6 +44,7 @@

import sample.tomcat.service.HelloWorldService;
import sample.tomcat.web.SampleController;

import static org.junit.Assert.assertEquals;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,18 @@ public ConfigurableApplicationContext run(String... args) {

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 {
// Create and configure the environment
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) {
Expand All @@ -287,8 +287,8 @@ public ConfigurableApplicationContext run(String... args) {
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);
Expand All @@ -298,15 +298,15 @@ public ConfigurableApplicationContext run(String... args) {
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();
Expand All @@ -317,8 +317,8 @@ public ConfigurableApplicationContext run(String... args) {
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();
Expand All @@ -330,13 +330,11 @@ public ConfigurableApplicationContext run(String... args) {
}
}

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) {
Expand Down Expand Up @@ -625,10 +623,10 @@ protected void afterRefresh(ConfigurableApplicationContext context, String[] arg
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()) {
Expand Down
Loading

0 comments on commit cf23b51

Please sign in to comment.