Final polish before 1.0.0.RC1

This commit is contained in:
Phillip Webb 2014-01-21 13:30:23 -08:00
parent 853b0a8027
commit ac54d7fe3c
67 changed files with 390 additions and 218 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"); * 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.
@ -53,6 +53,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
* Configuration triggered from {@link EndpointWebMvcAutoConfiguration} when a new * Configuration triggered from {@link EndpointWebMvcAutoConfiguration} when a new
* {@link EmbeddedServletContainer} running on a different port is required. * {@link EmbeddedServletContainer} running on a different port is required.
* *
* @author Dave Syer
* @see EndpointWebMvcAutoConfiguration * @see EndpointWebMvcAutoConfiguration
*/ */
@Configuration @Configuration

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"); * 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.
@ -48,11 +48,9 @@ import org.springframework.messaging.support.ExecutorSubscribableChannel;
import com.codahale.metrics.MetricRegistry; import com.codahale.metrics.MetricRegistry;
/** /**
* <p>
* {@link EnableAutoConfiguration Auto-configuration} for metrics services. Creates * {@link EnableAutoConfiguration Auto-configuration} for metrics services. Creates
* user-facing {@link GaugeService} and {@link CounterService} instances, and also back * user-facing {@link GaugeService} and {@link CounterService} instances, and also back
* end repositories to catch the data pumped into them. * end repositories to catch the data pumped into them. </p>
* </p>
* <p> * <p>
* An {@link InMemoryMetricRepository} is always created unless another * An {@link InMemoryMetricRepository} is always created unless another
* {@link MetricRepository} is already provided by the user. In general, even if metric * {@link MetricRepository} is already provided by the user. In general, even if metric

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"); * 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.
@ -21,7 +21,6 @@ import javax.validation.constraints.Pattern;
/** /**
* Abstract base for {@link Endpoint} implementations. * Abstract base for {@link Endpoint} implementations.
* <p>
* *
* @author Phillip Webb * @author Phillip Webb
* @author Christian Dupuis * @author Christian Dupuis

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"); * 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.
@ -35,7 +35,6 @@ public class TraceEndpoint extends AbstractEndpoint<List<Trace>> {
/** /**
* Create a new {@link TraceEndpoint} instance. * Create a new {@link TraceEndpoint} instance.
*
* @param repository the trace repository * @param repository the trace repository
*/ */
public TraceEndpoint(TraceRepository repository) { public TraceEndpoint(TraceRepository repository) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013 the original author or authors. * Copyright 2013-2014 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.
@ -184,8 +184,6 @@ public class EndpointMBeanExporter extends MBeanExporter implements SmartLifecyc
return builder.toString(); return builder.toString();
} }
// SmartLifeCycle implementation
@Override @Override
public final int getPhase() { public final int getPhase() {
return this.phase; return this.phase;

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"); * 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.
@ -46,7 +46,6 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
* @author Phillip Webb * @author Phillip Webb
* @author Christian Dupuis * @author Christian Dupuis
* @author Dave Syer * @author Dave Syer
*
*/ */
public class EndpointHandlerMapping extends RequestMappingHandlerMapping implements public class EndpointHandlerMapping extends RequestMappingHandlerMapping implements
ApplicationContextAware { ApplicationContextAware {

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"); * 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.
@ -17,18 +17,26 @@
package org.springframework.boot.actuate.endpoint.mvc; package org.springframework.boot.actuate.endpoint.mvc;
import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
/** /**
* Adapter class to expose {@link Endpoint}s as {@link MvcEndpoint}s.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class GenericMvcEndpoint implements MvcEndpoint { public class EndpointMvcAdapter implements MvcEndpoint {
private Endpoint<?> delegate; private final Endpoint<?> delegate;
public GenericMvcEndpoint(Endpoint<?> delegate) { /**
* Create a new {@link EndpointMvcAdapter}.
* @param delegate the underlying {@link Endpoint} to adapt.
*/
public EndpointMvcAdapter(Endpoint<?> delegate) {
Assert.notNull(delegate, "Delegate must not be null");
this.delegate = delegate; this.delegate = delegate;
} }
@ -49,11 +57,9 @@ public class GenericMvcEndpoint implements MvcEndpoint {
} }
@Override @Override
public Class<?> getEndpointType() { @SuppressWarnings("rawtypes")
@SuppressWarnings("unchecked") public Class<? extends Endpoint> getEndpointType() {
Class<? extends Endpoint<?>> type = (Class<? extends Endpoint<?>>) this.delegate return this.delegate.getClass();
.getClass();
return type;
} }
} }

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"); * 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.
@ -27,9 +27,11 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
/** /**
* Adapter to expose {@link EnvironmentEndpoint} as an {@link MvcEndpoint}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class EnvironmentMvcEndpoint extends GenericMvcEndpoint implements public class EnvironmentMvcEndpoint extends EndpointMvcAdapter implements
EnvironmentAware { EnvironmentAware {
private Environment environment; private Environment environment;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013 the original author or authors. * Copyright 2013-2014 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.
@ -38,8 +38,7 @@ import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ServletWrappingController; import org.springframework.web.servlet.mvc.ServletWrappingController;
/** /**
* {@link Endpoint} implementation to register the Jolokia infrastructure with the Boot * {@link MvcEndpoint} to expose Jolokia.
* management subsystem.
* *
* @author Christian Dupuis * @author Christian Dupuis
*/ */
@ -110,7 +109,8 @@ public class JolokiaMvcEndpoint implements MvcEndpoint, InitializingBean,
} }
@Override @Override
public Class<?> getEndpointType() { @SuppressWarnings("rawtypes")
public Class<? extends Endpoint> getEndpointType() {
return null; return null;
} }

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"); * 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.
@ -18,17 +18,19 @@ package org.springframework.boot.actuate.endpoint.mvc;
import java.util.Map; import java.util.Map;
import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.actuate.web.ErrorController; import org.springframework.boot.actuate.web.ErrorController;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
/** /**
* Special endpoint for handling "/error" path when the management servlet is in a child * Special {@link MvcEndpoint} for handling "/error" path when the management servlet is
* context. The regular {@link ErrorController} should be available there but because of * in a child context. The regular {@link ErrorController} should be available there but
* the way the handler mappings are set up it will not be detected. * because of the way the handler mappings are set up it will not be detected.
* *
* @author Dave Syer * @author Dave Syer
*/ */
@ -36,9 +38,11 @@ import org.springframework.web.context.request.RequestContextHolder;
public class ManagementErrorEndpoint implements MvcEndpoint { public class ManagementErrorEndpoint implements MvcEndpoint {
private final ErrorController controller; private final ErrorController controller;
private String path;
private final String path;
public ManagementErrorEndpoint(String path, ErrorController controller) { public ManagementErrorEndpoint(String path, ErrorController controller) {
Assert.notNull(controller, "Controller must not be null");
this.path = path; this.path = path;
this.controller = controller; this.controller = controller;
} }
@ -61,7 +65,8 @@ public class ManagementErrorEndpoint implements MvcEndpoint {
} }
@Override @Override
public Class<?> getEndpointType() { @SuppressWarnings("rawtypes")
public Class<? extends Endpoint> getEndpointType() {
return null; return null;
} }
} }

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"); * 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.
@ -25,11 +25,13 @@ import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
/** /**
* Adapter to expose {@link MetricsEndpoint} as an {@link MvcEndpoint}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class MetricsMvcEndpoint extends GenericMvcEndpoint { public class MetricsMvcEndpoint extends EndpointMvcAdapter {
private MetricsEndpoint delegate; private final MetricsEndpoint delegate;
public MetricsMvcEndpoint(MetricsEndpoint delegate) { public MetricsMvcEndpoint(MetricsEndpoint delegate) {
super(delegate); super(delegate);

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"); * 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.
@ -29,10 +29,22 @@ import org.springframework.boot.actuate.endpoint.Endpoint;
*/ */
public interface MvcEndpoint { public interface MvcEndpoint {
/**
* Return the MVC path of the endpoint.
*/
String getPath(); String getPath();
/**
* Return if the endpoint exposes sensitive information.
*/
boolean isSensitive(); boolean isSensitive();
Class<?> getEndpointType(); /**
* Return the type of {@link Endpoint} exposed, or {@code null} if this
* {@link MvcEndpoint} exposes information that cannot be represented as a traditional
* {@link Endpoint}.
*/
@SuppressWarnings("rawtypes")
Class<? extends Endpoint> getEndpointType();
} }

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"); * 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.
@ -60,7 +60,7 @@ public class MvcEndpoints implements ApplicationContextAware, InitializingBean {
Endpoint.class).values(); Endpoint.class).values();
for (Endpoint<?> endpoint : delegates) { for (Endpoint<?> endpoint : delegates) {
if (isGenericEndpoint(endpoint.getClass())) { if (isGenericEndpoint(endpoint.getClass())) {
this.endpoints.add(new GenericMvcEndpoint(endpoint)); this.endpoints.add(new EndpointMvcAdapter(endpoint));
} }
} }
} }
@ -85,4 +85,4 @@ public class MvcEndpoints implements ApplicationContextAware, InitializingBean {
&& !MvcEndpoint.class.isAssignableFrom(type); && !MvcEndpoint.class.isAssignableFrom(type);
} }
} }

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"); * 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.
@ -22,9 +22,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
/** /**
* Adapter to expose {@link ShutdownEndpoint} as an {@link MvcEndpoint}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class ShutdownMvcEndpoint extends GenericMvcEndpoint { public class ShutdownMvcEndpoint extends EndpointMvcAdapter {
public ShutdownMvcEndpoint(ShutdownEndpoint delegate) { public ShutdownMvcEndpoint(ShutdownEndpoint delegate) {
super(delegate); super(delegate);

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"); * 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.
@ -17,7 +17,7 @@
package org.springframework.boot.actuate.health; package org.springframework.boot.actuate.health;
/** /**
* Default implementation of {@link HealthIndicator} that simply returns "ok". * Default implementation of {@link HealthIndicator} that simply returns {@literal "ok"}.
* *
* @author Dave Syer * @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"); * 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.
@ -49,7 +49,6 @@ public abstract class AbstractMetricExporter implements Exporter {
/** /**
* The earliest time for which data will be exported. * The earliest time for which data will be exported.
*
* @param earliestTimestamp the timestamp to set * @param earliestTimestamp the timestamp to set
*/ */
public void setEarliestTimestamp(Date earliestTimestamp) { public void setEarliestTimestamp(Date earliestTimestamp) {
@ -58,7 +57,6 @@ public abstract class AbstractMetricExporter implements Exporter {
/** /**
* Ignore timestamps (export all metrics). * Ignore timestamps (export all metrics).
*
* @param ignoreTimestamps the flag to set * @param ignoreTimestamps the flag to set
*/ */
public void setIgnoreTimestamps(boolean ignoreTimestamps) { public void setIgnoreTimestamps(boolean ignoreTimestamps) {
@ -96,7 +94,6 @@ public abstract class AbstractMetricExporter implements Exporter {
* prefixes). If the metrics to be exported partition into groups identified by a * prefixes). If the metrics to be exported partition into groups identified by a
* String, subclasses should override this method. Otherwise the default should be * String, subclasses should override this method. Otherwise the default should be
* fine (iteration over all metrics). * fine (iteration over all metrics).
*
* @return groups of metrics to iterate over (default singleton empty string) * @return groups of metrics to iterate over (default singleton empty string)
*/ */
protected Iterable<String> groups() { protected Iterable<String> groups() {
@ -105,7 +102,6 @@ public abstract class AbstractMetricExporter implements Exporter {
/** /**
* Write the values associated with a group. * Write the values associated with a group.
*
* @param group the group to write * @param group the group to write
* @param values the values to write * @param values the values to write
*/ */
@ -113,10 +109,9 @@ public abstract class AbstractMetricExporter implements Exporter {
/** /**
* Get the next group of metrics to write. * Get the next group of metrics to write.
*
* @param group the group name to write * @param group the group name to write
* @return some metrics to write * @return some metrics to write
*/ */
protected abstract Iterable<Metric<?>> next(String group); protected abstract Iterable<Metric<?>> next(String group);
} }

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"); * 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.
@ -37,6 +37,7 @@ public class InMemoryMetricRepository implements MetricRepository, MultiMetricRe
PrefixMetricReader { PrefixMetricReader {
private SimpleInMemoryRepository<Metric<?>> metrics = new SimpleInMemoryRepository<Metric<?>>(); private SimpleInMemoryRepository<Metric<?>> metrics = new SimpleInMemoryRepository<Metric<?>>();
private Collection<String> groups = new HashSet<String>(); private Collection<String> groups = new HashSet<String>();
@Override @Override

View File

@ -43,6 +43,7 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
private static final String DEFAULT_METRICS_PREFIX = "spring.groups."; private static final String DEFAULT_METRICS_PREFIX = "spring.groups.";
private String prefix = DEFAULT_METRICS_PREFIX; private String prefix = DEFAULT_METRICS_PREFIX;
private String keys = this.prefix + "keys"; private String keys = this.prefix + "keys";
private BoundZSetOperations<String, String> zSetOperations; private BoundZSetOperations<String, String> zSetOperations;
@ -57,7 +58,6 @@ public class RedisMultiMetricRepository implements MultiMetricRepository {
/** /**
* The prefix for all metrics keys. * The prefix for all metrics keys.
*
* @param prefix the prefix to set for all metrics keys * @param prefix the prefix to set for all metrics keys
*/ */
public void setPrefix(String prefix) { public void setPrefix(String prefix) {

View File

@ -1,3 +1,19 @@
/*
* 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.
* 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.boot.actuate.metrics.repository.redis; package org.springframework.boot.actuate.metrics.repository.redis;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
@ -8,6 +24,8 @@ import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
/** /**
* General Utils for working with Redis.
*
* @author Luke Taylor * @author Luke Taylor
*/ */
class RedisUtils { class RedisUtils {

View File

@ -1,3 +1,19 @@
/*
* 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.
* 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.boot.actuate.metrics.rich; package org.springframework.boot.actuate.metrics.rich;
import org.springframework.util.Assert; import org.springframework.util.Assert;

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"); * 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.
@ -30,6 +30,7 @@ import com.codahale.metrics.Timer;
/** /**
* A {@link MetricWriter} that send data to a Codahale {@link MetricRegistry} based on a * A {@link MetricWriter} that send data to a Codahale {@link MetricRegistry} based on a
* naming convention: * naming convention:
*
* <ul> * <ul>
* <li>Updates to {@link #increment(Delta)} with names in "meter.*" are treated as * <li>Updates to {@link #increment(Delta)} with names in "meter.*" are treated as
* {@link Meter} events</li> * {@link Meter} events</li>
@ -49,7 +50,8 @@ public class CodahaleMetricWriter implements MetricWriter {
private final MetricRegistry registry; private final MetricRegistry registry;
/** /**
* @param registry * Create a new {@link CodahaleMetricWriter} instance.
* @param registry the underlying metric registry
*/ */
public CodahaleMetricWriter(MetricRegistry registry) { public CodahaleMetricWriter(MetricRegistry registry) {
this.registry = registry; this.registry = registry;
@ -94,17 +96,20 @@ public class CodahaleMetricWriter implements MetricWriter {
this.registry.remove(metricName); this.registry.remove(metricName);
} }
/**
* Simple {@link Gauge} implementation to {@literal double} value.
*/
private static class SimpleGauge implements Gauge<Double> { private static class SimpleGauge implements Gauge<Double> {
private final double gauge; private final double value;
private SimpleGauge(double gauge) { private SimpleGauge(double value) {
this.gauge = gauge; this.value = value;
} }
@Override @Override
public Double getValue() { public Double getValue() {
return this.gauge; return this.value;
} }
} }

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"); * 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.
@ -54,9 +54,7 @@ public class DefaultCounterService implements CounterService {
if (metricName.startsWith("counter") || metricName.startsWith("meter")) { if (metricName.startsWith("counter") || metricName.startsWith("meter")) {
return metricName; return metricName;
} }
else { return "counter." + metricName;
return "counter." + metricName;
}
} }
} }

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"); * 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.
@ -46,9 +46,7 @@ public class DefaultGaugeService implements GaugeService {
|| metricName.startsWith("timer")) { || metricName.startsWith("timer")) {
return metricName; return metricName;
} }
else { return "gauge." + metricName;
return "gauge." + metricName;
}
} }
} }

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"); * 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.
@ -81,6 +81,9 @@ public class ManagementServerProperties implements SecurityPrequisite {
return this.security; return this.security;
} }
/**
* Security configuration.
*/
public static class Security { public static class Security {
private boolean enabled = true; private boolean enabled = true;
@ -116,11 +119,8 @@ public class ManagementServerProperties implements SecurityPrequisite {
} }
private static Security maybeCreateSecurity() { private static Security maybeCreateSecurity() {
if (ClassUtils return (ClassUtils.isPresent("org.springframework.security.core.Authentication",
.isPresent("org.springframework.security.core.Authentication", null)) { null) ? new Security() : null);
return new Security();
}
return null;
} }
} }

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"); * 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.
@ -36,7 +36,6 @@ public interface ErrorController {
/** /**
* Extract a useful model of the error from the request attributes. * Extract a useful model of the error from the request attributes.
*
* @param attributes the request attributes * @param attributes the request attributes
* @param trace flag to indicate that stack trace information should be included * @param trace flag to indicate that stack trace information should be included
* @return a model containing error messages and codes etc. * @return a model containing error messages and codes etc.

View File

@ -260,7 +260,8 @@ public class EndpointWebMvcAutoConfigurationTests {
} }
@Override @Override
public Class<?> getEndpointType() { @SuppressWarnings("rawtypes")
public Class<? extends Endpoint> getEndpointType() {
return Endpoint.class; return Endpoint.class;
} }

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"); * 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.
@ -146,7 +146,7 @@ public class EndpointHandlerMappingTests {
} }
private static class TestMvcEndpoint extends GenericMvcEndpoint { private static class TestMvcEndpoint extends EndpointMvcAdapter {
public TestMvcEndpoint(TestEndpoint delegate) { public TestMvcEndpoint(TestEndpoint delegate) {
super(delegate); super(delegate);
@ -154,7 +154,7 @@ public class EndpointHandlerMappingTests {
} }
private static class TestActionEndpoint extends GenericMvcEndpoint { private static class TestActionEndpoint extends EndpointMvcAdapter {
public TestActionEndpoint(TestEndpoint delegate) { public TestActionEndpoint(TestEndpoint delegate) {
super(delegate); super(delegate);

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"); * 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.
@ -54,10 +54,9 @@ public class RedisServer implements TestRule {
try { try {
this.resource = obtainResource(); this.resource = obtainResource();
} }
catch (Exception e) { catch (Exception ex) {
maybeCleanup(); maybeCleanup();
return failOrSkip(ex);
return failOrSkip(e);
} }
return new Statement() { return new Statement() {
@ -82,17 +81,18 @@ public class RedisServer implements TestRule {
}; };
} }
private Statement failOrSkip(Exception e) { private Statement failOrSkip(Exception exception) {
String serversRequired = System.getenv(EXTERNAL_SERVERS_REQUIRED); String serversRequired = System.getenv(EXTERNAL_SERVERS_REQUIRED);
if ("true".equalsIgnoreCase(serversRequired)) { if ("true".equalsIgnoreCase(serversRequired)) {
logger.error(this.resourceDescription + " IS REQUIRED BUT NOT AVAILABLE", e); logger.error(this.resourceDescription + " IS REQUIRED BUT NOT AVAILABLE",
exception);
fail(this.resourceDescription + " IS NOT AVAILABLE"); fail(this.resourceDescription + " IS NOT AVAILABLE");
// Never reached, here to satisfy method signature // Never reached, here to satisfy method signature
return null; return null;
} }
else { else {
logger.error(this.resourceDescription + " IS NOT AVAILABLE, SKIPPING TESTS", logger.error(this.resourceDescription + " IS NOT AVAILABLE, SKIPPING TESTS",
e); exception);
return new Statement() { return new Statement() {
@Override @Override

View File

@ -40,7 +40,6 @@ import org.springframework.util.StringUtils;
* the {@link AutoConfigurationReport} to the log. Reports are logged at the * the {@link AutoConfigurationReport} to the log. Reports are logged at the
* {@link LogLevel#DEBUG DEBUG} level unless there was a problem, in which case they are * {@link LogLevel#DEBUG DEBUG} level unless there was a problem, in which case they are
* the {@link LogLevel#INFO INFO} level is used. * the {@link LogLevel#INFO INFO} level is used.
*
* <p> * <p>
* This initializer is not intended to be shared across multiple application context * This initializer is not intended to be shared across multiple application context
* instances. * instances.

View File

@ -39,20 +39,17 @@ import org.springframework.core.io.support.SpringFactoriesLoader;
* have {@code tomat-embedded.jar} on your classpath you are likely to want a * have {@code tomat-embedded.jar} on your classpath you are likely to want a
* {@link TomcatEmbeddedServletContainerFactory} (unless you have defined your own * {@link TomcatEmbeddedServletContainerFactory} (unless you have defined your own
* {@link EmbeddedServletContainerFactory} bean). * {@link EmbeddedServletContainerFactory} bean).
*
* <p> * <p>
* Auto-configuration tries to be as intelligent as possible and will back-away as you * Auto-configuration tries to be as intelligent as possible and will back-away as you
* define more of your own configuration. You can always manually {@link #exclude()} any * define more of your own configuration. You can always manually {@link #exclude()} any
* configuration that you never want to apply. Auto-configuration is always applied after * configuration that you never want to apply. Auto-configuration is always applied after
* user-defined beans have been registered. * user-defined beans have been registered.
*
* <p> * <p>
* The package of the class that is annotated with {@code @EnableAutoConfiguration} has * The package of the class that is annotated with {@code @EnableAutoConfiguration} has
* specific significance and is often used as a 'default'. For example, it will be used * specific significance and is often used as a 'default'. For example, it will be used
* when scanning for {@code @Entity} classes. It is generally recommended that you place * when scanning for {@code @Entity} classes. It is generally recommended that you place
* {@code @EnableAutoConfiguration} in a root package so that all sub-packages and classes * {@code @EnableAutoConfiguration} in a root package so that all sub-packages and classes
* can be searched. * can be searched.
*
* <p> * <p>
* Auto-configuration classes are regular Spring {@link Configuration} beans. They are * Auto-configuration classes are regular Spring {@link Configuration} beans. They are
* located using the {@link SpringFactoriesLoader} mechanism (keyed against this class). * located using the {@link SpringFactoriesLoader} mechanism (keyed against this class).

View File

@ -33,6 +33,8 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
/** /**
* Basic {@link BatchConfigurer} implementation.
*
* @author Dave Syer * @author Dave Syer
*/ */
@Component @Component
@ -41,15 +43,28 @@ public class BasicBatchConfigurer implements BatchConfigurer {
private static Log logger = LogFactory.getLog(BasicBatchConfigurer.class); private static Log logger = LogFactory.getLog(BasicBatchConfigurer.class);
private DataSource dataSource; private DataSource dataSource;
private EntityManagerFactory entityManagerFactory; private EntityManagerFactory entityManagerFactory;
private PlatformTransactionManager transactionManager; private PlatformTransactionManager transactionManager;
private JobRepository jobRepository; private JobRepository jobRepository;
private JobLauncher jobLauncher; private JobLauncher jobLauncher;
/**
* Create a new {@link BasicBatchConfigurer} instance.
* @param dataSource the underlying data source
*/
public BasicBatchConfigurer(DataSource dataSource) { public BasicBatchConfigurer(DataSource dataSource) {
this(dataSource, null); this(dataSource, null);
} }
/**
* Create a new {@link BasicBatchConfigurer} instance.
* @param dataSource the underlying data source
* @param entityManagerFactory the entity manager factory (or {@code null})
*/
public BasicBatchConfigurer(DataSource dataSource, public BasicBatchConfigurer(DataSource dataSource,
EntityManagerFactory entityManagerFactory) { EntityManagerFactory entityManagerFactory) {
this.entityManagerFactory = entityManagerFactory; this.entityManagerFactory = entityManagerFactory;

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"); * 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.
@ -38,7 +38,8 @@ import org.springframework.stereotype.Component;
@Component @Component
public class BatchDatabaseInitializer implements EnvironmentAware { public class BatchDatabaseInitializer implements EnvironmentAware {
private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/batch/core/schema-@@platform@@.sql"; private static final String DEFAULT_SCHEMA_LOCATION = "classpath:org/springframework/"
+ "batch/core/schema-@@platform@@.sql";
@Autowired @Autowired
private DataSource dataSource; private DataSource dataSource;

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"); * 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.
@ -198,16 +198,26 @@ class OnBeanCondition extends SpringBootCondition implements ConfigurationCondit
if (this.types.isEmpty() && this.names.isEmpty()) { if (this.types.isEmpty() && this.names.isEmpty()) {
addDeducedBeanType(context, metadata, this.types); addDeducedBeanType(context, metadata, this.types);
} }
Assert.isTrue( Assert.isTrue(hasAtLeastOne(this.types, this.names, this.annotations),
!this.types.isEmpty() || !this.names.isEmpty() annotationName(annotationType) + " annotations must "
|| !this.annotations.isEmpty(), + "specify at least one bean (type, name or annotation)");
"@"
+ ClassUtils.getShortName(annotationType)
+ " annotations must specify at least one bean (type, name or annotation)");
this.strategy = (SearchStrategy) metadata.getAnnotationAttributes( this.strategy = (SearchStrategy) metadata.getAnnotationAttributes(
annotationType.getName()).get("search"); annotationType.getName()).get("search");
} }
private boolean hasAtLeastOne(List<?>... lists) {
for (List<?> list : lists) {
if (!list.isEmpty()) {
return true;
}
}
return false;
}
private String annotationName(Class<?> annotationType) {
return "@" + ClassUtils.getShortName(annotationType);
}
@SuppressWarnings({ "unchecked", "rawtypes" }) @SuppressWarnings({ "unchecked", "rawtypes" })
private void collect(MultiValueMap<String, Object> attributes, String key, private void collect(MultiValueMap<String, Object> attributes, String key,
List<String> destination) { List<String> destination) {

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"); * 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.
@ -34,7 +34,8 @@ import org.springframework.web.context.support.StandardServletEnvironment;
*/ */
class OnWebApplicationCondition extends SpringBootCondition { class OnWebApplicationCondition extends SpringBootCondition {
private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context.support.GenericWebApplicationContext"; private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context."
+ "support.GenericWebApplicationContext";
@Override @Override
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,

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"); * 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.
@ -31,9 +31,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -177,6 +177,9 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
} }
/**
* Base {@link Condition} for non-embedded database checks.
*/
static abstract class NonEmbeddedDatabaseCondition extends SpringBootCondition { static abstract class NonEmbeddedDatabaseCondition extends SpringBootCondition {
protected abstract String getDataSourceClassName(); protected abstract String getDataSourceClassName();
@ -243,6 +246,10 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
} }
} }
/**
* {@link Condition} to detect when a commons-dbcp {@code BasicDataSource} backed
* database is used.
*/
static class BasicDatabaseCondition extends NonEmbeddedDatabaseCondition { static class BasicDatabaseCondition extends NonEmbeddedDatabaseCondition {
private Condition tomcatCondition = new TomcatDatabaseCondition(); private Condition tomcatCondition = new TomcatDatabaseCondition();
@ -256,12 +263,15 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
public ConditionOutcome getMatchOutcome(ConditionContext context, public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) { AnnotatedTypeMetadata metadata) {
if (matches(context, metadata, this.tomcatCondition)) { if (matches(context, metadata, this.tomcatCondition)) {
return ConditionOutcome.noMatch("tomcat DataSource"); return ConditionOutcome.noMatch("Tomcat DataSource");
} }
return super.getMatchOutcome(context, metadata); return super.getMatchOutcome(context, metadata);
} }
} }
/**
* {@link Condition} to detect when a Tomcat DataSource backed database is used.
*/
static class TomcatDatabaseCondition extends NonEmbeddedDatabaseCondition { static class TomcatDatabaseCondition extends NonEmbeddedDatabaseCondition {
@Override @Override
@ -271,6 +281,9 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
} }
/**
* {@link Condition} to detect when an embedded database is used.
*/
static class EmbeddedDatabaseCondition extends SpringBootCondition { static class EmbeddedDatabaseCondition extends SpringBootCondition {
private SpringBootCondition tomcatCondition = new TomcatDatabaseCondition(); private SpringBootCondition tomcatCondition = new TomcatDatabaseCondition();
@ -293,6 +306,9 @@ public class DataSourceAutoConfiguration implements EnvironmentAware {
} }
} }
/**
* {@link Condition} to detect when a database is configured.
*/
static class DatabaseCondition extends SpringBootCondition { static class DatabaseCondition extends SpringBootCondition {
private SpringBootCondition tomcatCondition = new TomcatDatabaseCondition(); private SpringBootCondition tomcatCondition = new TomcatDatabaseCondition();

View File

@ -80,16 +80,14 @@ public class JmsTemplateAutoConfiguration {
private ActiveMQConnectionFactoryProperties config; private ActiveMQConnectionFactoryProperties config;
@Bean @Bean
ConnectionFactory jmsConnectionFactory() { public ConnectionFactory jmsConnectionFactory() {
if (this.config.isPooled()) { if (this.config.isPooled()) {
PooledConnectionFactory pool = new PooledConnectionFactory(); PooledConnectionFactory pool = new PooledConnectionFactory();
pool.setConnectionFactory(new ActiveMQConnectionFactory(this.config pool.setConnectionFactory(new ActiveMQConnectionFactory(this.config
.getBrokerURL())); .getBrokerURL()));
return pool; return pool;
} }
else { return new ActiveMQConnectionFactory(this.config.getBrokerURL());
return new ActiveMQConnectionFactory(this.config.getBrokerURL());
}
} }
} }
@ -108,9 +106,7 @@ public class JmsTemplateAutoConfiguration {
if (this.inMemory) { if (this.inMemory) {
return "vm://localhost"; return "vm://localhost";
} }
else { return this.brokerURL;
return this.brokerURL;
}
} }
public void setBrokerURL(String brokerURL) { public void setBrokerURL(String brokerURL) {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2013 the original author or authors. * Copyright 2012-2014 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.
@ -27,7 +27,6 @@ import org.springframework.jmx.export.MBeanExporter;
/** /**
* {@link EnableAutoConfiguration Auto-configuration} to enable/disable Spring's * {@link EnableAutoConfiguration Auto-configuration} to enable/disable Spring's
* {@link EnableMBeanExport} mechanism based on configuration properties. * {@link EnableMBeanExport} mechanism based on configuration properties.
*
* <p> * <p>
* To disable auto export of annotation beans set <code>spring.jmx.enabled: false</code>. * To disable auto export of annotation beans set <code>spring.jmx.enabled: false</code>.
* *

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"); * 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.
@ -48,7 +48,6 @@ public class ReactorAutoConfiguration {
@ConditionalOnMissingBean(Environment.class) @ConditionalOnMissingBean(Environment.class)
@EnableReactor @EnableReactor
protected static class ReactorConfiguration { protected static class ReactorConfiguration {
} }
} }

View File

@ -33,6 +33,11 @@ import org.springframework.security.config.annotation.ObjectPostProcessor;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer; import org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer;
/**
* Configuration for a Spring Security in-memory {@link AuthenticationManager}.
*
* @author Dave Syer
*/
@Configuration @Configuration
@ConditionalOnBean(ObjectPostProcessor.class) @ConditionalOnBean(ObjectPostProcessor.class)
@ConditionalOnMissingBean(AuthenticationManager.class) @ConditionalOnMissingBean(AuthenticationManager.class)
@ -69,4 +74,4 @@ public class AuthenticationManagerConfiguration {
} }
} }

View File

@ -16,6 +16,7 @@
package org.springframework.boot.autoconfigure.security; package org.springframework.boot.autoconfigure.security;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -24,6 +25,11 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
/**
* {@link EnableAutoConfiguration Auto-configuration} for Spring Security.
*
* @author Dave Syer
*/
@Configuration @Configuration
@ConditionalOnClass(AuthenticationManager.class) @ConditionalOnClass(AuthenticationManager.class)
@EnableConfigurationProperties @EnableConfigurationProperties
@ -37,4 +43,4 @@ public class SecurityAutoConfiguration {
return new SecurityProperties(); return new SecurityProperties();
} }
} }

View File

@ -87,7 +87,6 @@ import org.springframework.web.servlet.support.RequestDataValueProcessor;
@ConditionalOnClass({ EnableWebSecurity.class }) @ConditionalOnClass({ EnableWebSecurity.class })
@ConditionalOnMissingBean(WebSecurityConfiguration.class) @ConditionalOnMissingBean(WebSecurityConfiguration.class)
@ConditionalOnWebApplication @ConditionalOnWebApplication
// @ConditionalOnMissingBean(annotation = EnableWebSecurity.class)
public class SpringBootWebSecurityConfiguration { public class SpringBootWebSecurityConfiguration {
private static List<String> DEFAULT_IGNORED = Arrays.asList("/css/**", "/js/**", private static List<String> DEFAULT_IGNORED = Arrays.asList("/css/**", "/js/**",
@ -107,6 +106,39 @@ public class SpringBootWebSecurityConfiguration {
return new IgnoredPathsWebSecurityConfigurerAdapter(); return new IgnoredPathsWebSecurityConfigurerAdapter();
} }
public static void configureHeaders(HeadersConfigurer<?> configurer,
SecurityProperties.Headers headers) throws Exception {
if (headers.getHsts() != Headers.HSTS.none) {
boolean includeSubdomains = headers.getHsts() == Headers.HSTS.all;
HstsHeaderWriter writer = new HstsHeaderWriter(includeSubdomains);
writer.setRequestMatcher(AnyRequestMatcher.INSTANCE);
configurer.addHeaderWriter(writer);
}
if (headers.isContentType()) {
configurer.contentTypeOptions();
}
if (headers.isXss()) {
configurer.xssProtection();
}
if (headers.isCache()) {
configurer.cacheControl();
}
if (headers.isFrame()) {
configurer.frameOptions();
}
}
public static List<String> getIgnored(SecurityProperties security) {
List<String> ignored = new ArrayList<String>(security.getIgnored());
if (ignored.isEmpty()) {
ignored.addAll(DEFAULT_IGNORED);
}
else if (ignored.contains("none")) {
ignored.remove("none");
}
return ignored;
}
// Get the ignored paths in early // Get the ignored paths in early
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
private static class IgnoredPathsWebSecurityConfigurerAdapter implements private static class IgnoredPathsWebSecurityConfigurerAdapter implements
@ -135,10 +167,12 @@ public class SpringBootWebSecurityConfiguration {
@ConditionalOnExpression("${security.basic.enabled:true}") @ConditionalOnExpression("${security.basic.enabled:true}")
@Configuration @Configuration
protected static class WebMvcSecurityConfigurationConditions { protected static class WebMvcSecurityConfigurationConditions {
@Configuration @Configuration
@EnableWebMvcSecurity @EnableWebMvcSecurity
protected static class DefaultWebMvcSecurityConfiguration { protected static class DefaultWebMvcSecurityConfiguration {
} }
} }
// Pull in a plain @EnableWebSecurity if Spring MVC is not available // Pull in a plain @EnableWebSecurity if Spring MVC is not available
@ -223,37 +257,4 @@ public class SpringBootWebSecurityConfiguration {
} }
public static void configureHeaders(HeadersConfigurer<?> configurer,
SecurityProperties.Headers headers) throws Exception {
if (headers.getHsts() != Headers.HSTS.none) {
boolean includeSubdomains = headers.getHsts() == Headers.HSTS.all;
HstsHeaderWriter writer = new HstsHeaderWriter(includeSubdomains);
writer.setRequestMatcher(AnyRequestMatcher.INSTANCE);
configurer.addHeaderWriter(writer);
}
if (headers.isContentType()) {
configurer.contentTypeOptions();
}
if (headers.isXss()) {
configurer.xssProtection();
}
if (headers.isCache()) {
configurer.cacheControl();
}
if (headers.isFrame()) {
configurer.frameOptions();
}
}
public static List<String> getIgnored(SecurityProperties security) {
List<String> ignored = new ArrayList<String>(security.getIgnored());
if (ignored.isEmpty()) {
ignored.addAll(DEFAULT_IGNORED);
}
else if (ignored.contains("none")) {
ignored.remove("none");
}
return ignored;
}
} }

View File

@ -106,7 +106,7 @@ public final class CommandLineInvoker {
lines.add(line); lines.add(line);
} }
} }
catch (IOException e) { catch (IOException ex) {
throw new RuntimeException("Failed to read standard output"); throw new RuntimeException("Failed to read standard output");
} }
return lines; return lines;

View File

@ -112,11 +112,14 @@ public class CommandCompleter extends StringsCompleter {
} }
this.console.drawLine(); this.console.drawLine();
} }
catch (IOException e) { catch (IOException ex) {
Log.error(e.getMessage() + " (" + e.getClass().getName() + ")"); Log.error(ex.getMessage() + " (" + ex.getClass().getName() + ")");
} }
} }
/**
* Encapsulated options and usage help.
*/
private static class OptionHelpLine { private static class OptionHelpLine {
private final String options; private final String options;

View File

@ -20,7 +20,7 @@ import jline.console.completer.ArgumentCompleter.ArgumentList;
import jline.console.completer.ArgumentCompleter.WhitespaceArgumentDelimiter; import jline.console.completer.ArgumentCompleter.WhitespaceArgumentDelimiter;
/** /**
* Escape ware variant of {@link WhitespaceArgumentDelimiter}. * Escape aware variant of {@link WhitespaceArgumentDelimiter}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */

View File

@ -103,7 +103,7 @@ class RunProcessCommand extends AbstractCommand {
} }
reader.close(); reader.close();
} }
catch (Exception e) { catch (Exception ex) {
} }
}; };
}.start(); }.start();
@ -135,7 +135,7 @@ class RunProcessCommand extends AbstractCommand {
this.process = null; this.process = null;
return true; return true;
} }
catch (InterruptedException e) { catch (InterruptedException ex) {
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
} }
} }

View File

@ -64,8 +64,7 @@ import org.springframework.boot.cli.util.ResourceUtils;
* *
* <li>Generated class files can also be loaded using * <li>Generated class files can also be loaded using
* {@link ClassLoader#getResource(String)}</li> * {@link ClassLoader#getResource(String)}</li>
* * </ul>
* <ul>
* *
* @author Phillip Webb * @author Phillip Webb
* @author Dave Syer * @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"); * 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.
@ -61,7 +61,6 @@ public final class RepositoryConfigurationFactory {
/** /**
* Add the default local M2 cache directory as a remote repository. Only do this if * Add the default local M2 cache directory as a remote repository. Only do this if
* the local cache location has been changed from the default. * the local cache location has been changed from the default.
*
* @param repositoryConfiguration * @param repositoryConfiguration
*/ */
public static void addDefaultCacheAsRespository( public static void addDefaultCacheAsRespository(

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"); * 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.
@ -54,7 +54,7 @@ public final class JreProxySelector implements ProxySelector {
URI uri = new URI(repository.getUrl()).parseServerAuthority(); URI uri = new URI(repository.getUrl()).parseServerAuthority();
proxies = java.net.ProxySelector.getDefault().select(uri); proxies = java.net.ProxySelector.getDefault().select(uri);
} }
catch (Exception e) { catch (Exception ex) {
// URL invalid or not accepted by selector or no selector at all, simply use // URL invalid or not accepted by selector or no selector at all, simply use
// no proxy // no proxy
} }
@ -113,7 +113,7 @@ public final class JreProxySelector implements ProxySelector {
try { try {
url = new URL(context.getRepository().getUrl()); url = new URL(context.getRepository().getUrl());
} }
catch (Exception e) { catch (Exception ex) {
url = null; url = null;
} }
@ -133,7 +133,7 @@ public final class JreProxySelector implements ProxySelector {
System.getProperty("http.proxyPassword")); System.getProperty("http.proxyPassword"));
} }
} }
catch (SecurityException e) { catch (SecurityException ex) {
// oh well, let's hope the proxy can do without auth // oh well, let's hope the proxy can do without auth
} }
} }

View File

@ -28,5 +28,9 @@ import org.eclipse.aether.graph.Dependency;
*/ */
public interface ManagedDependenciesFactory { public interface ManagedDependenciesFactory {
/**
* Returns the managed dependencies.
*/
List<Dependency> getManagedDependencies(); List<Dependency> getManagedDependencies();
} }

View File

@ -34,8 +34,7 @@ public final class RepositoryConfiguration {
private final boolean snapshotsEnabled; private final boolean snapshotsEnabled;
/** /**
* Creates a new {@code RepositoryConfiguration}. * Creates a new {@code RepositoryConfiguration} instance.
*
* @param name The name of the repository * @param name The name of the repository
* @param uri The uri of the repository * @param uri The uri of the repository
* @param snapshotsEnabled {@code true} if the repository should enable access to * @param snapshotsEnabled {@code true} if the repository should enable access to

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"); * 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.
@ -101,7 +101,6 @@ public class GroovyBeansTransformation implements ASTTransformation {
/** /**
* Extract a top-level <code>beans{}</code> closure from inside this block if * Extract a top-level <code>beans{}</code> closure from inside this block if
* there is one. Removes it from the block at the same time. * there is one. Removes it from the block at the same time.
*
* @param block a block statement (class definition) * @param block a block statement (class definition)
* @return a beans Closure if one can be found, null otherwise * @return a beans Closure if one can be found, null otherwise
*/ */
@ -128,9 +127,7 @@ public class GroovyBeansTransformation implements ASTTransformation {
} }
} }
} }
return null; return null;
} }
} }
} }

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"); * 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.
@ -22,9 +22,14 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.boot.cli.compiler.autoconfigure.SpringMobileCompilerAutoConfiguration;
/**
* Pseudo annotation used to trigger {@link SpringMobileCompilerAutoConfiguration}.
*/
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface EnableDeviceResolver { public @interface EnableDeviceResolver {
} }

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"); * 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.
@ -22,9 +22,13 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.boot.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
/**
* Pseudo annotation used to trigger {@link SpringIntegrationCompilerAutoConfiguration}.
*/
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@ -32,4 +36,4 @@ import org.springframework.context.annotation.ImportResource;
@ImportResource("classpath:/org/springframework/boot/groovy/integration.xml") @ImportResource("classpath:/org/springframework/boot/groovy/integration.xml")
public @interface EnableIntegrationPatterns { public @interface EnableIntegrationPatterns {
} }

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"); * 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.
@ -22,9 +22,14 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.springframework.boot.cli.compiler.autoconfigure.JmsCompilerAutoConfiguration;
/**
* Pseudo annotation used to trigger {@link JmsCompilerAutoConfiguration}.
*/
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface EnableJmsMessaging { public @interface EnableJmsMessaging {
} }

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"); * 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.
@ -28,6 +28,8 @@ import java.util.Map;
import org.codehaus.groovy.control.CompilationFailedException; import org.codehaus.groovy.control.CompilationFailedException;
/** /**
* Helpful utilties for working with Groovy {@link Template}s.
*
* @author Dave Syer * @author Dave Syer
*/ */
public abstract class GroovyTemplate { public abstract class GroovyTemplate {

View File

@ -50,9 +50,9 @@ public class SampleMongoApplicationTests {
output.contains("firstName='Alice', lastName='Smith'")); output.contains("firstName='Alice', lastName='Smith'"));
} }
private boolean serverNotRunning(IllegalStateException e) { private boolean serverNotRunning(IllegalStateException ex) {
@SuppressWarnings("serial") @SuppressWarnings("serial")
NestedCheckedException nested = new NestedCheckedException("failed", e) { NestedCheckedException nested = new NestedCheckedException("failed", ex) {
}; };
if (nested.contains(IOException.class)) { if (nested.contains(IOException.class)) {
Throwable root = nested.getRootCause(); Throwable root = nested.getRootCause();

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"); * 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.
@ -19,11 +19,12 @@ package org.springframework.boot.gradle
import org.springframework.boot.loader.tools.Layout import org.springframework.boot.loader.tools.Layout
import org.springframework.boot.loader.tools.Layouts import org.springframework.boot.loader.tools.Layouts
/** /**
* Gradle DSL Extension for 'Spring Boot'. Most of the time Spring Boot can guess the * Gradle DSL Extension for 'Spring Boot'. Most of the time Spring Boot can guess the
* settings in this extension, but occasionally you might need to explicitly set one * settings in this extension, but occasionally you might need to explicitly set one
* or two of them. E.g. * or two of them. E.g.
* *
* <pre> * <pre>
* apply plugin: "spring-boot" * apply plugin: "spring-boot"
* springBoot { * springBoot {
@ -53,7 +54,7 @@ public class SpringBootPluginExtension {
String mainClass String mainClass
/** /**
* The name of the ivy configuration name to treat as 'provided' (when packaging * The name of the ivy configuration name to treat as 'provided' (when packaging
* those dependencies in a separate path). If not specified 'providedRuntime' will * those dependencies in a separate path). If not specified 'providedRuntime' will
* be used. * be used.
*/ */
@ -73,15 +74,14 @@ public class SpringBootPluginExtension {
* The layout of the archive if it can't be derived from the file extension. * The layout of the archive if it can't be derived from the file extension.
* Valid values are JAR, WAR, ZIP, DIR (for exploded zip file). ZIP and DIR * Valid values are JAR, WAR, ZIP, DIR (for exploded zip file). ZIP and DIR
* are actually synonymous, and should be used if there is no MANIFEST.MF * are actually synonymous, and should be used if there is no MANIFEST.MF
* available, or if you want the MANIFEST.MF 'Main-Class' to be * available, or if you want the MANIFEST.MF 'Main-Class' to be
* PropertiesLauncher. Gradle will coerce literal String values to the * PropertiesLauncher. Gradle will coerce literal String values to the
* correct type. * correct type.
*/ */
LayoutType layout; LayoutType layout;
/** /**
* Convenience method for use in a custom task. * Convenience method for use in a custom task.
*
* @return the Layout to use or null if not explicitly set * @return the Layout to use or null if not explicitly set
*/ */
Layout convertLayout() { Layout convertLayout() {

View File

@ -1,3 +1,18 @@
/*
* 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.
* 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.boot.gradle.task; package org.springframework.boot.gradle.task;
@ -13,7 +28,7 @@ import org.springframework.boot.loader.tools.LibraryScope;
/** /**
* Expose Gradle {@link Configuration}s as {@link Libraries}. * Expose Gradle {@link Configuration}s as {@link Libraries}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */
class ProjectLibraries implements Libraries { class ProjectLibraries implements Libraries {
@ -26,7 +41,6 @@ class ProjectLibraries implements Libraries {
/** /**
* Create a new {@link ProjectLibraries} instance of the specified {@link Project}. * Create a new {@link ProjectLibraries} instance of the specified {@link Project}.
*
* @param project the gradle project * @param project the gradle project
*/ */
public ProjectLibraries(Project project) { public ProjectLibraries(Project project) {
@ -35,7 +49,6 @@ class ProjectLibraries implements Libraries {
/** /**
* Set the name of the provided configuration. Defaults to 'providedRuntime'. * Set the name of the provided configuration. Defaults to 'providedRuntime'.
*
* @param providedConfigurationName the providedConfigurationName to set * @param providedConfigurationName the providedConfigurationName to set
*/ */
public void setProvidedConfigurationName(String providedConfigurationName) { public void setProvidedConfigurationName(String providedConfigurationName) {

View File

@ -95,8 +95,8 @@ public class RunApp extends DefaultTask {
getLogger().info("Looking for main in: " + main.getOutput().getClassesDir()); getLogger().info("Looking for main in: " + main.getOutput().getClassesDir());
try { try {
return MainClassFinder.findMainClass(main.getOutput().getClassesDir()); return MainClassFinder.findMainClass(main.getOutput().getClassesDir());
} catch (IOException e) { } catch (IOException ex) {
throw new IllegalStateException("Cannot find main class", e); throw new IllegalStateException("Cannot find main class", ex);
} }
} }

View File

@ -51,7 +51,6 @@ import org.springframework.boot.loader.util.SystemPropertyUtils;
* {@link Launcher} for archives with user-configured classpath and main class via a * {@link Launcher} for archives with user-configured classpath and main class via a
* properties file. This model is often more flexible and more amenable to creating * properties file. This model is often more flexible and more amenable to creating
* well-behaved OS-level services than a model based on executable jars. * well-behaved OS-level services than a model based on executable jars.
*
* <p> * <p>
* Looks in various places for a properties file to extract loader settings, defaulting to * Looks in various places for a properties file to extract loader settings, defaulting to
* <code>application.properties</code> either on the current classpath or in the current * <code>application.properties</code> either on the current classpath or in the current
@ -62,7 +61,6 @@ import org.springframework.boot.loader.util.SystemPropertyUtils;
* <code>file:</code> or any valid URL). Once that file is located turns it into * <code>file:</code> or any valid URL). Once that file is located turns it into
* Properties and extracts optional values (which can also be provided overridden as * Properties and extracts optional values (which can also be provided overridden as
* System properties in case the file doesn't exist): * System properties in case the file doesn't exist):
*
* <ul> * <ul>
* <li><code>loader.path</code>: a comma-separated list of directories to append to the * <li><code>loader.path</code>: a comma-separated list of directories to append to the
* classpath (containing file resources and/or nested archives in *.jar or *.zip). * classpath (containing file resources and/or nested archives in *.jar or *.zip).
@ -345,7 +343,7 @@ public class PropertiesLauncher extends Launcher {
try { try {
return loaderClass.getConstructor(ClassLoader.class).newInstance(parent); return loaderClass.getConstructor(ClassLoader.class).newInstance(parent);
} }
catch (NoSuchMethodException e) { catch (NoSuchMethodException ex) {
// Ignore and try with URLs // Ignore and try with URLs
} }

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"); * 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.
@ -28,11 +28,14 @@ import java.util.jar.Manifest;
import org.springframework.boot.loader.AsciiBytes; import org.springframework.boot.loader.AsciiBytes;
/** /**
* Decorator to apply an {@link Archive.EntryFilter} to an existing {@link Archive}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class FilteredArchive extends Archive { public class FilteredArchive extends Archive {
private Archive parent; private Archive parent;
private EntryFilter filter; private EntryFilter filter;
public FilteredArchive(Archive parent, EntryFilter filter) { public FilteredArchive(Archive parent, EntryFilter filter) {

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"); * 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.
@ -22,14 +22,11 @@ import java.util.Set;
/** /**
* Helper class for resolving placeholders in texts. Usually applied to file paths. * Helper class for resolving placeholders in texts. Usually applied to file paths.
*
* <p> * <p>
* A text may contain {@code $ ...} placeholders, to be resolved as system properties: * A text may contain {@code $ ...} placeholders, to be resolved as system properties:
* e.g. {@code $ user.dir} . Default values can be supplied using the ":" separator * e.g. {@code $ user.dir} . Default values can be supplied using the ":" separator
* between key and value. * between key and value.
*
* <p> * <p>
*
* Adapted from Spring. * Adapted from Spring.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
@ -40,13 +37,19 @@ import java.util.Set;
*/ */
public abstract class SystemPropertyUtils { public abstract class SystemPropertyUtils {
/** Prefix for system property placeholders: "${" */ /**
* Prefix for system property placeholders: "${"
*/
public static final String PLACEHOLDER_PREFIX = "${"; public static final String PLACEHOLDER_PREFIX = "${";
/** Suffix for system property placeholders: "}" */ /**
* Suffix for system property placeholders: "}"
*/
public static final String PLACEHOLDER_SUFFIX = "}"; public static final String PLACEHOLDER_SUFFIX = "}";
/** Value separator for system property placeholders: ":" */ /**
* Value separator for system property placeholders: ":"
*/
public static final String VALUE_SEPARATOR = ":"; public static final String VALUE_SEPARATOR = ":";
private static final String SIMPLE_PREFIX = PLACEHOLDER_PREFIX.substring(1); private static final String SIMPLE_PREFIX = PLACEHOLDER_PREFIX.substring(1);
@ -166,7 +169,6 @@ public abstract class SystemPropertyUtils {
* Search the System properties and environment variables for a value with the * Search the System properties and environment variables for a value with the
* provided key. Environment variables in <code>UPPER_CASE</code> style are allowed * provided key. Environment variables in <code>UPPER_CASE</code> style are allowed
* where System properties would normally be <code>lower.case</code>. * where System properties would normally be <code>lower.case</code>.
*
* @param key the key to resolve * @param key the key to resolve
* @param text optional extra context for an error message if the key resolution fails * @param text optional extra context for an error message if the key resolution fails
* (e.g. if System properties are not accessible) * (e.g. if System properties are not accessible)

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"); * 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.
@ -88,14 +88,14 @@ public class SimpleJsonParser implements JsonParser {
try { try {
return Long.valueOf(json); return Long.valueOf(json);
} }
catch (NumberFormatException e) { catch (NumberFormatException ex) {
// ignore // ignore
} }
try { try {
return Double.valueOf(json); return Double.valueOf(json);
} }
catch (NumberFormatException e) { catch (NumberFormatException ex) {
// ignore // ignore
} }

View File

@ -109,8 +109,8 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer {
ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"), ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"),
connector)).toString(); connector)).toString();
} }
catch (Exception e) { catch (Exception ex) {
return "could not determine port ( " + e.getMessage() + ")"; return "could not determine port ( " + ex.getMessage() + ")";
} }
} }

View File

@ -1,7 +1,5 @@
package org.springframework.boot.context.embedded.tomcat;
/* /*
* 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"); * 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.
@ -16,6 +14,8 @@ package org.springframework.boot.context.embedded.tomcat;
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.context.embedded.tomcat;
import org.apache.catalina.loader.WebappClassLoader; import org.apache.catalina.loader.WebappClassLoader;
/** /**

View File

@ -0,0 +1,23 @@
/*
* 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.
* 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.
*/
/**
* Classes and utilities that are useful when unit-testing Spring Boot applications.
* This package is only intended for use in 'src/test' and should not be used in your
* 'src/main' code.
*/
package org.springframework.boot.test;

View File

@ -394,12 +394,14 @@ public class EnableConfigurationPropertiesTests {
@Configuration @Configuration
protected static class DefaultConfiguration { protected static class DefaultConfiguration {
@Bean @Bean
public TestProperties testProperties() { public TestProperties testProperties() {
TestProperties test = new TestProperties(); TestProperties test = new TestProperties();
test.setName("bar"); test.setName("bar");
return test; return test;
} }
} }
@Configuration @Configuration
@ -410,10 +412,12 @@ public class EnableConfigurationPropertiesTests {
@EnableConfigurationProperties @EnableConfigurationProperties
@Configuration @Configuration
public static class ExampleConfig { public static class ExampleConfig {
@Bean @Bean
public External external() { public External external() {
return new External(); return new External();
} }
} }
@EnableConfigurationProperties(External.class) @EnableConfigurationProperties(External.class)
@ -461,6 +465,7 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties(name = "spring_test_external") @ConfigurationProperties(name = "spring_test_external")
public static class SystemEnvVar { public static class SystemEnvVar {
public String getVal() { public String getVal() {
return this.val; return this.val;
} }
@ -475,6 +480,7 @@ public class EnableConfigurationPropertiesTests {
@Component @Component
protected static class TestConsumer { protected static class TestConsumer {
@Autowired @Autowired
private TestProperties properties; private TestProperties properties;
@ -495,7 +501,9 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties @ConfigurationProperties
protected static class NestedProperties { protected static class NestedProperties {
private String name; private String name;
private Nested nested = new Nested(); private Nested nested = new Nested();
public void setName(String name) { public void setName(String name) {
@ -507,6 +515,7 @@ public class EnableConfigurationPropertiesTests {
} }
protected static class Nested { protected static class Nested {
private String name; private String name;
public void setName(String name) { public void setName(String name) {
@ -514,15 +523,18 @@ public class EnableConfigurationPropertiesTests {
} }
} }
} }
@ConfigurationProperties @ConfigurationProperties
protected static class BaseProperties { protected static class BaseProperties {
private String name; private String name;
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
protected static class DerivedProperties extends BaseProperties { protected static class DerivedProperties extends BaseProperties {
@ -530,8 +542,11 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties @ConfigurationProperties
protected static class TestProperties { protected static class TestProperties {
private String name; private String name;
private int[] array; private int[] array;
private List<Integer> list = new ArrayList<Integer>(); private List<Integer> list = new ArrayList<Integer>();
// No getter - you should be able to bind to a write-only bean // No getter - you should be able to bind to a write-only bean
@ -551,6 +566,7 @@ public class EnableConfigurationPropertiesTests {
public List<Integer> getList() { public List<Integer> getList() {
return this.list; return this.list;
} }
} }
@ConfigurationProperties(ignoreUnknownFields = false) @ConfigurationProperties(ignoreUnknownFields = false)
@ -559,12 +575,10 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties(name = "spring.foo") @ConfigurationProperties(name = "spring.foo")
protected static class EmbeddedTestProperties extends TestProperties { protected static class EmbeddedTestProperties extends TestProperties {
} }
@ConfigurationProperties(ignoreUnknownFields = false, ignoreNestedProperties = true) @ConfigurationProperties(ignoreUnknownFields = false, ignoreNestedProperties = true)
protected static class IgnoreNestedTestProperties extends TestProperties { protected static class IgnoreNestedTestProperties extends TestProperties {
} }
@ConfigurationProperties @ConfigurationProperties
@ -600,6 +614,7 @@ public class EnableConfigurationPropertiesTests {
} }
protected static class MoreProperties { protected static class MoreProperties {
private String name; private String name;
public void setName(String name) { public void setName(String name) {
@ -611,6 +626,7 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties(path = "${binding.location:classpath:name.yml}") @ConfigurationProperties(path = "${binding.location:classpath:name.yml}")
protected static class ResourceBindingProperties { protected static class ResourceBindingProperties {
private String name; private String name;
public void setName(String name) { public void setName(String name) {
@ -623,6 +639,7 @@ public class EnableConfigurationPropertiesTests {
@EnableConfigurationProperties @EnableConfigurationProperties
@ConfigurationProperties(path = "${binding.location:classpath:map.yml}") @ConfigurationProperties(path = "${binding.location:classpath:map.yml}")
protected static class ResourceBindingPropertiesWithMap { protected static class ResourceBindingPropertiesWithMap {
private Map<String, String> mymap; private Map<String, String> mymap;
public void setMymap(Map<String, String> mymap) { public void setMymap(Map<String, String> mymap) {