Commit 6c2ea464 authored by Phillip Webb's avatar Phillip Webb

Polish

parent fd1cbed5
...@@ -20,13 +20,13 @@ package org.springframework.boot.actuate.metrics.writer; ...@@ -20,13 +20,13 @@ package org.springframework.boot.actuate.metrics.writer;
* Simple writer for counters (metrics that increment). * Simple writer for counters (metrics that increment).
* *
* @author Dave Syer * @author Dave Syer
* @since 1.3.0
*/ */
public interface CounterWriter { public interface CounterWriter {
/** /**
* Increment the value of a metric (or decrement if the delta is negative). The name * Increment the value of a metric (or decrement if the delta is negative). The name
* of the delta is the name of the metric to increment. * of the delta is the name of the metric to increment.
*
* @param delta the amount to increment by * @param delta the amount to increment by
*/ */
void increment(Delta<?> delta); void increment(Delta<?> delta);
...@@ -34,9 +34,8 @@ public interface CounterWriter { ...@@ -34,9 +34,8 @@ public interface CounterWriter {
/** /**
* Reset the value of a metric, usually to zero value. Implementations can discard the * Reset the value of a metric, usually to zero value. Implementations can discard the
* old values if desired, but may choose not to. This operation is optional (some * old values if desired, but may choose not to. This operation is optional (some
* implementations may not be able to fulfil the contract, in which case they should * implementations may not be able to fulfill the contract, in which case they should
* simply do nothing). * simply do nothing).
*
* @param metricName the name to reset * @param metricName the name to reset
*/ */
void reset(String metricName); void reset(String metricName);
......
...@@ -22,6 +22,7 @@ import org.springframework.boot.actuate.metrics.Metric; ...@@ -22,6 +22,7 @@ import org.springframework.boot.actuate.metrics.Metric;
* Writer for gauge values (simple metric with a number value). * Writer for gauge values (simple metric with a number value).
* *
* @author Dave Syer * @author Dave Syer
* @since 1.3.0
*/ */
public interface GaugeWriter { public interface GaugeWriter {
......
...@@ -22,6 +22,8 @@ import org.springframework.boot.actuate.metrics.Metric; ...@@ -22,6 +22,8 @@ import org.springframework.boot.actuate.metrics.Metric;
* Basic strategy for write operations on {@link Metric} data. * Basic strategy for write operations on {@link Metric} data.
* *
* @author Dave Syer * @author Dave Syer
* @see GaugeWriter
* @see CounterWriter
*/ */
public interface MetricWriter extends GaugeWriter, CounterWriter { public interface MetricWriter extends GaugeWriter, CounterWriter {
......
...@@ -66,7 +66,7 @@ public class AuthenticationAuditListener implements ...@@ -66,7 +66,7 @@ public class AuthenticationAuditListener implements
this.webListener.process(this, event); this.webListener.process(this, event);
} }
else if (event instanceof AuthenticationSuccessEvent) { else if (event instanceof AuthenticationSuccessEvent) {
onAuthenticationEvent((AuthenticationSuccessEvent) event); onAuthenticationSuccessEvent((AuthenticationSuccessEvent) event);
} }
} }
...@@ -78,7 +78,7 @@ public class AuthenticationAuditListener implements ...@@ -78,7 +78,7 @@ public class AuthenticationAuditListener implements
"AUTHENTICATION_FAILURE", data)); "AUTHENTICATION_FAILURE", data));
} }
private void onAuthenticationEvent(AuthenticationSuccessEvent event) { private void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();
if (event.getAuthentication().getDetails() != null) { if (event.getAuthentication().getDetails() != null) {
data.put("details", event.getAuthentication().getDetails()); data.put("details", event.getAuthentication().getDetails());
......
...@@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Configuration properties for OAuth2 Authorization server. * Configuration properties for OAuth2 Authorization server.
* *
* @author Dave Syer * @author Dave Syer
* @since 1.3.0
*/ */
@ConfigurationProperties("security.oauth2.authorization") @ConfigurationProperties("security.oauth2.authorization")
public class AuthorizationServerProperties { public class AuthorizationServerProperties {
......
...@@ -94,13 +94,16 @@ public class OAuth2AuthorizationServerConfiguration ...@@ -94,13 +94,16 @@ public class OAuth2AuthorizationServerConfiguration
.scopes(this.details.getScope().toArray(new String[0])); .scopes(this.details.getScope().toArray(new String[0]));
if (this.details.getAutoApproveScopes() != null) { if (this.details.getAutoApproveScopes() != null) {
builder.autoApprove(this.details.getAutoApproveScopes().toArray(new String[0])); builder.autoApprove(
this.details.getAutoApproveScopes().toArray(new String[0]));
} }
if (this.details.getAccessTokenValiditySeconds() != null) { if (this.details.getAccessTokenValiditySeconds() != null) {
builder.accessTokenValiditySeconds(this.details.getAccessTokenValiditySeconds()); builder.accessTokenValiditySeconds(
this.details.getAccessTokenValiditySeconds());
} }
if (this.details.getRefreshTokenValiditySeconds() != null) { if (this.details.getRefreshTokenValiditySeconds() != null) {
builder.refreshTokenValiditySeconds(this.details.getRefreshTokenValiditySeconds()); builder.refreshTokenValiditySeconds(
this.details.getRefreshTokenValiditySeconds());
} }
if (this.details.getRegisteredRedirectUri() != null) { if (this.details.getRegisteredRedirectUri() != null) {
builder.redirectUris( builder.redirectUris(
......
...@@ -114,9 +114,7 @@ public class OAuth2ResourceServerConfiguration { ...@@ -114,9 +114,7 @@ public class OAuth2ResourceServerConfiguration {
Environment environment = context.getEnvironment(); Environment environment = context.getEnvironment();
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
"security.oauth2.resource."); "security.oauth2.resource.");
String client = environment if (hasOAuthClientId(environment)) {
.resolvePlaceholders("${security.oauth2.client.client-id:}");
if (StringUtils.hasText(client)) {
return ConditionOutcome.match("found client id"); return ConditionOutcome.match("found client id");
} }
if (!resolver.getSubProperties("jwt").isEmpty()) { if (!resolver.getSubProperties("jwt").isEmpty()) {
...@@ -137,6 +135,12 @@ public class OAuth2ResourceServerConfiguration { ...@@ -137,6 +135,12 @@ public class OAuth2ResourceServerConfiguration {
+ "JWT resource nor authorization server"); + "JWT resource nor authorization server");
} }
private boolean hasOAuthClientId(Environment environment) {
RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment,
"security.oauth2.client.");
return StringUtils.hasLength(resolver.getProperty("client-id", ""));
}
} }
@ConditionalOnBean(AuthorizationServerEndpointsConfiguration.class) @ConditionalOnBean(AuthorizationServerEndpointsConfiguration.class)
......
...@@ -140,4 +140,5 @@ public class UserInfoTokenServices implements ResourceServerTokenServices { ...@@ -140,4 +140,5 @@ public class UserInfoTokenServices implements ResourceServerTokenServices {
"Could not fetch user details"); "Could not fetch user details");
} }
} }
} }
...@@ -32,6 +32,7 @@ import org.springframework.util.ReflectionUtils; ...@@ -32,6 +32,7 @@ import org.springframework.util.ReflectionUtils;
* {@link RestartListener} that prepares Log4J2 for an application restart. * {@link RestartListener} that prepares Log4J2 for an application restart.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 1.3.0
*/ */
public class Log4J2RestartListener implements RestartListener { public class Log4J2RestartListener implements RestartListener {
......
...@@ -20,6 +20,7 @@ package org.springframework.boot.devtools.restart; ...@@ -20,6 +20,7 @@ package org.springframework.boot.devtools.restart;
* Listener that is notified of application restarts. * Listener that is notified of application restarts.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 1.3.0
*/ */
public interface RestartListener { public interface RestartListener {
......
...@@ -411,6 +411,7 @@ and mark it as disabled. For example: ...@@ -411,6 +411,7 @@ and mark it as disabled. For example:
---- ----
[[howto-add-a-servlet-filter-or-listener-using-scanning]] [[howto-add-a-servlet-filter-or-listener-using-scanning]]
==== Add Servlets, Filters, and Listeners using classpath scanning ==== Add Servlets, Filters, and Listeners using classpath scanning
`@WebServlet`, `@WebFilter`, and `@WebListener` annotated classes can be automatically `@WebServlet`, `@WebFilter`, and `@WebListener` annotated classes can be automatically
......
...@@ -186,13 +186,14 @@ If the https://github.com/mikekelly/hal-browser[HAL Browser] is on the classpath ...@@ -186,13 +186,14 @@ If the https://github.com/mikekelly/hal-browser[HAL Browser] is on the classpath
via its webjar (`org.webjars:hal-browser`), or via the `spring-data-rest-hal-browser` then via its webjar (`org.webjars:hal-browser`), or via the `spring-data-rest-hal-browser` then
an HTML "`discovery page`", in the form of the HAL Browser, is also provided. an HTML "`discovery page`", in the form of the HAL Browser, is also provided.
[[production-ready-endpoint-cors]] [[production-ready-endpoint-cors]]
=== CORS support === CORS support
http://en.wikipedia.org/wiki/Cross-origin_resource_sharing[Cross-origin resource sharing] http://en.wikipedia.org/wiki/Cross-origin_resource_sharing[Cross-origin resource sharing]
(CORS) is a http://www.w3.org/TR/cors/[W3C specification] that allows you to specify in a (CORS) is a http://www.w3.org/TR/cors/[W3C specification] that allows you to specify in a
flexible way what kind of cross domain requests are authorized. Actuator's MVC endpoints flexible way what kind of cross domain requests are authorized. Actuator's MVC endpoints
can be configured to support such scenario. can be configured to support such scenarios.
CORS support is disabled by default and is only enabled once the CORS support is disabled by default and is only enabled once the
`endpoints.cors.allowed-origins` property has been set. The configuration below permits `endpoints.cors.allowed-origins` property has been set. The configuration below permits
...@@ -208,6 +209,7 @@ TIP: Check {sc-spring-boot-actuator}/autoconfigure/EndpointCorsProperties.{sc-ex ...@@ -208,6 +209,7 @@ TIP: Check {sc-spring-boot-actuator}/autoconfigure/EndpointCorsProperties.{sc-ex
for a complete list of options. for a complete list of options.
[[production-ready-customizing-endpoints-programmatically]] [[production-ready-customizing-endpoints-programmatically]]
=== Adding custom endpoints === Adding custom endpoints
If you add a `@Bean` of type `Endpoint` then it will automatically be exposed over JMX and If you add a `@Bean` of type `Endpoint` then it will automatically be exposed over JMX and
...@@ -1076,16 +1078,13 @@ used by default if you are on Java 8 or if you are using Dropwizard metrics. ...@@ -1076,16 +1078,13 @@ used by default if you are on Java 8 or if you are using Dropwizard metrics.
[[production-ready-metric-writers]] [[production-ready-metric-writers]]
=== Metric writers, exporters and aggregation === Metric writers, exporters and aggregation
Spring Boot provides a couple of implementations of a marker interface called `Exporter`
Spring Boot provides a couple of implementations of a marker interface which can be used to copy metric readings from the in-memory buffers to a place where they
called `Exporter` which can be used to copy metric readings from the can be analyzed and displayed. Indeed, if you provide a `@Bean` that implements the
in-memory buffers to a place where they can be analyzed and `MetricWriter` interface (or `GaugeWriter` for simple use cases) and mark it
displayed. Indeed, if you provide a `@Bean` that implements the `@ExportMetricWriter`, then it will automatically be hooked up to an `Exporter` and fed
`MetricWriter` interface (or `GaugeWriter` for simple use cases) and metric updates every 5 seconds (configured via `spring.metrics.export.delay-millis`).
mark it `@ExportMetricWriter`, then it will automatically be hooked up In addition, any `MetricReader` that you define and mark as `@ExportMetricReader` will
to an `Exporter` and fed metric updates every 5 seconds (configured
via `spring.metrics.export.delay-millis`). In addition, any
`MetricReader` that you define and mark as `@ExportMetricReader` will
have its values exported by the default exporter. have its values exported by the default exporter.
The default exporter is a `MetricCopyExporter` which tries to optimize itself by not The default exporter is a `MetricCopyExporter` which tries to optimize itself by not
......
...@@ -330,16 +330,13 @@ To provide a concrete example, suppose you develop a `@Component` that uses a ...@@ -330,16 +330,13 @@ To provide a concrete example, suppose you develop a `@Component` that uses a
---- ----
On your application classpath (e.g. inside your jar) you can have an On your application classpath (e.g. inside your jar) you can have an
`application.properties` that provides a sensible default property `application.properties` that provides a sensible default property value for `name`. When
value for `name`. When running in a new environment, an running in a new environment, an `application.properties` can be provided outside of your
`application.properties` can be provided outside of your jar that jar that overrides the `name`; and for one-off testing, you can launch with a specific
overrides the `name`; and for one-off testing, you can launch with a command line switch (e.g. `java -jar app.jar --name="Spring"`).
specific command line switch (e.g. `java -jar app.jar
--name="Spring"`).
[TIP] [TIP]
==== ====
The `SPRING_APPLICATION_JSON` properties can be supplied on the The `SPRING_APPLICATION_JSON` properties can be supplied on the
command line with an environment variable. For example in a command line with an environment variable. For example in a
UN{asterisk}X shell: UN{asterisk}X shell:
...@@ -366,6 +363,7 @@ or as a JNDI variable `java:comp/env/spring.application.json`. ...@@ -366,6 +363,7 @@ or as a JNDI variable `java:comp/env/spring.application.json`.
==== ====
[[boot-features-external-config-random-values]] [[boot-features-external-config-random-values]]
=== Configuring random values === Configuring random values
The `RandomValuePropertySource` is useful for injecting random values (e.g. into secrets The `RandomValuePropertySource` is useful for injecting random values (e.g. into secrets
......
...@@ -27,9 +27,9 @@ work with other build systems (Ant for example), but they will not be particular ...@@ -27,9 +27,9 @@ work with other build systems (Ant for example), but they will not be particular
supported. supported.
[[using-boot-dependency-management]] [[using-boot-dependency-management]]
=== Dependency management === Dependency management
Each release of Spring Boot provides a curated list of dependencies it supports. In Each release of Spring Boot provides a curated list of dependencies it supports. In
practice, you do not need to provide a version for any of these dependencies in your practice, you do not need to provide a version for any of these dependencies in your
build configuration as Spring Boot is managing that for you. When you upgrade Spring build configuration as Spring Boot is managing that for you. When you upgrade Spring
...@@ -48,6 +48,7 @@ WARNING: Each release of Spring Boot is associated with a base version of the Sp ...@@ -48,6 +48,7 @@ WARNING: Each release of Spring Boot is associated with a base version of the Sp
Framework so we **highly** recommend you to not specify its version on your own. Framework so we **highly** recommend you to not specify its version on your own.
[[using-boot-maven]] [[using-boot-maven]]
=== Maven === Maven
Maven users can inherit from the `spring-boot-starter-parent` project to obtain sensible Maven users can inherit from the `spring-boot-starter-parent` project to obtain sensible
...@@ -105,6 +106,7 @@ TIP: Check the {github-code}/spring-boot-dependencies/pom.xml[`spring-boot-depen ...@@ -105,6 +106,7 @@ TIP: Check the {github-code}/spring-boot-dependencies/pom.xml[`spring-boot-depen
for a list of supported properties. for a list of supported properties.
[[using-boot-maven-without-a-parent]] [[using-boot-maven-without-a-parent]]
==== Using Spring Boot without the parent POM ==== Using Spring Boot without the parent POM
Not everyone likes inheriting from the `spring-boot-starter-parent` POM. You may have your Not everyone likes inheriting from the `spring-boot-starter-parent` POM. You may have your
...@@ -164,6 +166,7 @@ NOTE: In the example above, we specify a _BOM_ but any dependency type can be ov ...@@ -164,6 +166,7 @@ NOTE: In the example above, we specify a _BOM_ but any dependency type can be ov
that way. that way.
[[using-boot-maven-java-version]] [[using-boot-maven-java-version]]
==== Changing the Java version ==== Changing the Java version
The `spring-boot-starter-parent` chooses fairly conservative Java compatibility. If you The `spring-boot-starter-parent` chooses fairly conservative Java compatibility. If you
......
...@@ -73,6 +73,7 @@ ...@@ -73,6 +73,7 @@
<module>spring-boot-sample-property-validation</module> <module>spring-boot-sample-property-validation</module>
<module>spring-boot-sample-secure</module> <module>spring-boot-sample-secure</module>
<module>spring-boot-sample-secure-oauth2</module> <module>spring-boot-sample-secure-oauth2</module>
<module>spring-boot-sample-secure-oauth2-resource</module>
<module>spring-boot-sample-secure-sso</module> <module>spring-boot-sample-secure-sso</module>
<module>spring-boot-sample-servlet</module> <module>spring-boot-sample-servlet</module>
<module>spring-boot-sample-session-redis</module> <module>spring-boot-sample-session-redis</module>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package sample.secure.oauth2; package sample.secure.oauth2.resource;
import java.util.Date; import java.util.Date;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package sample.secure.oauth2; package sample.secure.oauth2.resource;
import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.CrudRepository;
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package sample.secure.oauth2;
package sample.secure.oauth2.resource;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
...@@ -23,8 +24,9 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R ...@@ -23,8 +24,9 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
@SpringBootApplication @SpringBootApplication
@EnableResourceServer @EnableResourceServer
public class SampleSecureOAuth2ResourceApplication extends ResourceServerConfigurerAdapter { public class SampleSecureOAuth2ResourceApplication
extends ResourceServerConfigurerAdapter {
@Override @Override
public void configure(HttpSecurity http) throws Exception { public void configure(HttpSecurity http) throws Exception {
http.antMatcher("/flights/**").authorizeRequests().anyRequest().authenticated(); http.antMatcher("/flights/**").authorizeRequests().anyRequest().authenticated();
......
package sample.secure.oauth2; /*
* Copyright 2012-2015 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.
*/
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; package sample.secure.oauth2.resource;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest; import org.springframework.boot.test.WebIntegrationTest;
...@@ -18,6 +30,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -18,6 +30,11 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
/** /**
* Series of automated integration tests to verify proper behavior of auto-configured, * Series of automated integration tests to verify proper behavior of auto-configured,
* OAuth2-secured system * OAuth2-secured system
...@@ -36,6 +53,7 @@ public class SampleSecureOAuth2ResourceApplicationTests { ...@@ -36,6 +53,7 @@ public class SampleSecureOAuth2ResourceApplicationTests {
FilterChainProxy filterChain; FilterChainProxy filterChain;
private MockMvc mvc; private MockMvc mvc;
@Before @Before
public void setUp() { public void setUp() {
this.mvc = webAppContextSetup(this.context).addFilters(this.filterChain).build(); this.mvc = webAppContextSetup(this.context).addFilters(this.filterChain).build();
...@@ -44,8 +62,8 @@ public class SampleSecureOAuth2ResourceApplicationTests { ...@@ -44,8 +62,8 @@ public class SampleSecureOAuth2ResourceApplicationTests {
@Test @Test
public void homePageAvailable() throws Exception { public void homePageAvailable() throws Exception {
this.mvc.perform(get("/").accept(MediaTypes.HAL_JSON)) this.mvc.perform(get("/").accept(MediaTypes.HAL_JSON)).andExpect(status().isOk())
.andExpect(status().isOk()).andDo(print()); .andDo(print());
} }
@Test @Test
......
...@@ -51,8 +51,7 @@ class TypeElementMembers { ...@@ -51,8 +51,7 @@ class TypeElementMembers {
private final Map<String, ExecutableElement> publicGetters = new LinkedHashMap<String, ExecutableElement>(); private final Map<String, ExecutableElement> publicGetters = new LinkedHashMap<String, ExecutableElement>();
private final Map<String, List<ExecutableElement>> publicSetters = private final Map<String, List<ExecutableElement>> publicSetters = new LinkedHashMap<String, List<ExecutableElement>>();
new LinkedHashMap<String, List<ExecutableElement>>();
TypeElementMembers(ProcessingEnvironment env, TypeElement element) { TypeElementMembers(ProcessingEnvironment env, TypeElement element) {
this.env = env; this.env = env;
...@@ -84,7 +83,8 @@ class TypeElementMembers { ...@@ -84,7 +83,8 @@ class TypeElementMembers {
} }
else if (isSetter(method)) { else if (isSetter(method)) {
String propertyName = getAccessorName(name); String propertyName = getAccessorName(name);
List<ExecutableElement> matchingSetters = this.publicSetters.get(propertyName); List<ExecutableElement> matchingSetters = this.publicSetters
.get(propertyName);
if (matchingSetters == null) { if (matchingSetters == null) {
matchingSetters = new ArrayList<ExecutableElement>(); matchingSetters = new ArrayList<ExecutableElement>();
this.publicSetters.put(propertyName, matchingSetters); this.publicSetters.put(propertyName, matchingSetters);
...@@ -97,7 +97,8 @@ class TypeElementMembers { ...@@ -97,7 +97,8 @@ class TypeElementMembers {
} }
} }
private ExecutableElement getMatchingSetter(List<ExecutableElement> candidates, TypeMirror type) { private ExecutableElement getMatchingSetter(List<ExecutableElement> candidates,
TypeMirror type) {
for (ExecutableElement candidate : candidates) { for (ExecutableElement candidate : candidates) {
TypeMirror paramType = candidate.getParameters().get(0).asType(); TypeMirror paramType = candidate.getParameters().get(0).asType();
if (this.env.getTypeUtils().isSameType(paramType, type)) { if (this.env.getTypeUtils().isSameType(paramType, type)) {
......
...@@ -40,7 +40,6 @@ import javax.lang.model.util.Types; ...@@ -40,7 +40,6 @@ import javax.lang.model.util.Types;
class TypeUtils { class TypeUtils {
private static final Map<TypeKind, Class<?>> PRIMITIVE_WRAPPERS; private static final Map<TypeKind, Class<?>> PRIMITIVE_WRAPPERS;
private static final Map<String, TypeKind> WRAPPER_TO_PRIMITIVE;
static { static {
Map<TypeKind, Class<?>> wrappers = new HashMap<TypeKind, Class<?>>(); Map<TypeKind, Class<?>> wrappers = new HashMap<TypeKind, Class<?>>();
...@@ -53,16 +52,15 @@ class TypeUtils { ...@@ -53,16 +52,15 @@ class TypeUtils {
wrappers.put(TypeKind.LONG, Long.class); wrappers.put(TypeKind.LONG, Long.class);
wrappers.put(TypeKind.SHORT, Short.class); wrappers.put(TypeKind.SHORT, Short.class);
PRIMITIVE_WRAPPERS = Collections.unmodifiableMap(wrappers); PRIMITIVE_WRAPPERS = Collections.unmodifiableMap(wrappers);
}
private static final Map<String, TypeKind> WRAPPER_TO_PRIMITIVE;
static {
Map<String, TypeKind> primitives = new HashMap<String, TypeKind>(); Map<String, TypeKind> primitives = new HashMap<String, TypeKind>();
primitives.put(Boolean.class.getName(), TypeKind.BOOLEAN); for (Map.Entry<TypeKind, Class<?>> entry : PRIMITIVE_WRAPPERS.entrySet()) {
primitives.put(Byte.class.getName(), TypeKind.BYTE); primitives.put(entry.getValue().getName(), entry.getKey());
primitives.put(Character.class.getName(), TypeKind.CHAR); }
primitives.put(Double.class.getName(), TypeKind.DOUBLE);
primitives.put(Float.class.getName(), TypeKind.FLOAT);
primitives.put(Integer.class.getName(), TypeKind.INT);
primitives.put(Long.class.getName(), TypeKind.LONG);
primitives.put(Short.class.getName(), TypeKind.SHORT);
WRAPPER_TO_PRIMITIVE = primitives; WRAPPER_TO_PRIMITIVE = primitives;
} }
...@@ -111,7 +109,6 @@ class TypeUtils { ...@@ -111,7 +109,6 @@ class TypeUtils {
|| this.env.getTypeUtils().isAssignable(type, this.mapType); || this.env.getTypeUtils().isAssignable(type, this.mapType);
} }
public boolean isEnclosedIn(Element candidate, TypeElement element) { public boolean isEnclosedIn(Element candidate, TypeElement element) {
if (candidate == null || element == null) { if (candidate == null || element == null) {
return false; return false;
...@@ -134,7 +131,8 @@ class TypeUtils { ...@@ -134,7 +131,8 @@ class TypeUtils {
public TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) { public TypeMirror getWrapperOrPrimitiveFor(TypeMirror typeMirror) {
Class<?> candidate = getWrapperFor(typeMirror); Class<?> candidate = getWrapperFor(typeMirror);
if (candidate != null) { if (candidate != null) {
return this.env.getElementUtils().getTypeElement(candidate.getName()).asType(); return this.env.getElementUtils().getTypeElement(candidate.getName())
.asType();
} }
TypeKind primitiveKind = getPrimitiveFor(typeMirror); TypeKind primitiveKind = getPrimitiveFor(typeMirror);
if (primitiveKind != null) { if (primitiveKind != null) {
......
...@@ -205,11 +205,9 @@ public class ConfigurationMetadataAnnotationProcessorTests { ...@@ -205,11 +205,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
ConfigurationMetadata metadata = compile(type); ConfigurationMetadata metadata = compile(type);
assertThat(metadata, containsGroup("not.deprecated").fromSource(type)); assertThat(metadata, containsGroup("not.deprecated").fromSource(type));
assertThat(metadata, containsProperty("not.deprecated.counter", Integer.class) assertThat(metadata, containsProperty("not.deprecated.counter", Integer.class)
.withNoDeprecation() .withNoDeprecation().fromSource(type));
.fromSource(type));
assertThat(metadata, containsProperty("not.deprecated.flag", Boolean.class) assertThat(metadata, containsProperty("not.deprecated.flag", Boolean.class)
.withNoDeprecation() .withNoDeprecation().fromSource(type));
.fromSource(type));
} }
@Test @Test
...@@ -217,10 +215,10 @@ public class ConfigurationMetadataAnnotationProcessorTests { ...@@ -217,10 +215,10 @@ public class ConfigurationMetadataAnnotationProcessorTests {
Class<?> type = BoxingPojo.class; Class<?> type = BoxingPojo.class;
ConfigurationMetadata metadata = compile(type); ConfigurationMetadata metadata = compile(type);
assertThat(metadata, containsGroup("boxing").fromSource(type)); assertThat(metadata, containsGroup("boxing").fromSource(type));
assertThat(metadata, containsProperty("boxing.flag", Boolean.class) assertThat(metadata,
.fromSource(type)); containsProperty("boxing.flag", Boolean.class).fromSource(type));
assertThat(metadata, containsProperty("boxing.counter", Integer.class) assertThat(metadata,
.fromSource(type)); containsProperty("boxing.counter", Integer.class).fromSource(type));
} }
@Test @Test
...@@ -366,12 +364,9 @@ public class ConfigurationMetadataAnnotationProcessorTests { ...@@ -366,12 +364,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
null, null, true, null); null, null, true, null);
writeAdditionalMetadata(property); writeAdditionalMetadata(property);
ConfigurationMetadata metadata = compile(SimpleProperties.class); ConfigurationMetadata metadata = compile(SimpleProperties.class);
assertThat(metadata, assertThat(metadata, containsProperty("simple.flag", Boolean.class)
containsProperty("simple.flag", Boolean.class) .fromSource(SimpleProperties.class).withDescription("A simple flag.")
.fromSource(SimpleProperties.class) .withDeprecation(null, null).withDefaultValue(is(true)));
.withDescription("A simple flag.")
.withDeprecation(null, null)
.withDefaultValue(is(true)));
assertThat(metadata.getItems().size(), is(4)); assertThat(metadata.getItems().size(), is(4));
} }
......
...@@ -19,8 +19,8 @@ package org.springframework.boot.configurationsample.specific; ...@@ -19,8 +19,8 @@ package org.springframework.boot.configurationsample.specific;
import org.springframework.boot.configurationsample.ConfigurationProperties; import org.springframework.boot.configurationsample.ConfigurationProperties;
/** /**
* Demonstrate the use of boxing/unboxing. Even if the type does not * Demonstrate the use of boxing/unboxing. Even if the type does not strictly match, it
* strictly match, it should still be detected. * should still be detected.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
......
...@@ -19,8 +19,8 @@ package org.springframework.boot.configurationsample.specific; ...@@ -19,8 +19,8 @@ package org.springframework.boot.configurationsample.specific;
import org.springframework.boot.configurationsample.ConfigurationProperties; import org.springframework.boot.configurationsample.ConfigurationProperties;
/** /**
* Demonstrate that an unrelated setter is not taken into account * Demonstrate that an unrelated setter is not taken into account to detect the deprecated
* to detect the deprecated flag. * flag.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
......
...@@ -63,11 +63,9 @@ public class LaunchedURLClassLoader extends URLClassLoader { ...@@ -63,11 +63,9 @@ public class LaunchedURLClassLoader extends URLClassLoader {
} }
/** /**
* Gets the resource with the given {@code name}. * Gets the resource with the given {@code name}. Unlike a standard
* <p> * {@link ClassLoader}, this method will first search the root class loader. If the
* Unlike a standard {@link ClassLoader}, this method will first search the root class * resource is not found, this method will call {@link #findResource(String)}.
* loader. If the resource is not found, this method will call
* {@link #findResource(String)}.
*/ */
@Override @Override
public URL getResource(String name) { public URL getResource(String name) {
...@@ -104,11 +102,10 @@ public class LaunchedURLClassLoader extends URLClassLoader { ...@@ -104,11 +102,10 @@ public class LaunchedURLClassLoader extends URLClassLoader {
} }
/** /**
* Gets the resources with the given {@code name}. * Gets the resources with the given {@code name}. Returns a combination of the
* <p> * resources found by {@link #findResources(String)} and from
* Returns a combination of the resources found by {@link #findResources(String)} and * {@link ClassLoader#getResources(String) getResources(String)} on the root class
* from {@link ClassLoader#getResources(String) getResources(String)} on the root * loader, if any.
* class loader, if any.
*/ */
@Override @Override
public Enumeration<URL> getResources(String name) throws IOException { public Enumeration<URL> getResources(String name) throws IOException {
......
...@@ -40,9 +40,8 @@ import org.springframework.context.annotation.Import; ...@@ -40,9 +40,8 @@ import org.springframework.context.annotation.Import;
public @interface EnableConfigurationProperties { public @interface EnableConfigurationProperties {
/** /**
* Convenient way to quickly register {@link ConfigurationProperties} annotated * Convenient way to quickly register {@link ConfigurationProperties} annotated beans
* beans with Spring. Standard Spring Beans will also be scanned regardless of * with Spring. Standard Spring Beans will also be scanned regardless of this value.
* this value.
* @return {@link ConfigurationProperties} annotated beans to register * @return {@link ConfigurationProperties} annotated beans to register
*/ */
Class<?>[] value() default {}; Class<?>[] value() default {};
......
...@@ -115,8 +115,9 @@ class EnableConfigurationPropertiesImportSelector implements ImportSelector { ...@@ -115,8 +115,9 @@ class EnableConfigurationPropertiesImportSelector implements ImportSelector {
ConfigurationProperties properties = AnnotationUtils.findAnnotation(type, ConfigurationProperties properties = AnnotationUtils.findAnnotation(type,
ConfigurationProperties.class); ConfigurationProperties.class);
Assert.notNull(properties, "No " + ConfigurationProperties.class.getSimpleName() Assert.notNull(properties,
+ " annotation found on '" + type.getName() + "'."); "No " + ConfigurationProperties.class.getSimpleName()
+ " annotation found on '" + type.getName() + "'.");
} }
} }
......
...@@ -31,6 +31,7 @@ import org.springframework.core.env.ConfigurableEnvironment; ...@@ -31,6 +31,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.StandardEnvironment;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -38,24 +39,29 @@ import org.springframework.web.context.support.StandardServletEnvironment; ...@@ -38,24 +39,29 @@ import org.springframework.web.context.support.StandardServletEnvironment;
/** /**
* An {@link EnvironmentPostProcessor} that parses JSON from * An {@link EnvironmentPostProcessor} that parses JSON from
* <code>spring.application.json</code> or equivalently * {@code spring.application.json} or equivalently
* {@link SpringApplicationJsonEnvironmentPostProcessor} and adds it as a map property * {@link SpringApplicationJsonEnvironmentPostProcessor} and adds it as a map property
* source to the {@link Environment}. The new properties are added with higher priority * source to the {@link Environment}. The new properties are added with higher priority
* than the system properties. * than the system properties.
* *
* @author Dave Syer * @author Dave Syer
* @author Phillip Webb
* @since 1.3.0
*/ */
public class SpringApplicationJsonEnvironmentPostProcessor public class SpringApplicationJsonEnvironmentPostProcessor
implements EnvironmentPostProcessor, Ordered { implements EnvironmentPostProcessor, Ordered {
private static final Log logger = LogFactory private static final String SERVLET_ENVIRONMENT_CLASS = "org.springframework.web."
.getLog(SpringApplicationJsonEnvironmentPostProcessor.class); + "context.support.StandardServletEnvironment";
/** /**
* The default order for the processor. * The default order for the processor.
*/ */
public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 5; public static final int DEFAULT_ORDER = Ordered.HIGHEST_PRECEDENCE + 5;
private static final Log logger = LogFactory
.getLog(SpringApplicationJsonEnvironmentPostProcessor.class);
private int order = DEFAULT_ORDER; private int order = DEFAULT_ORDER;
@Override @Override
...@@ -73,26 +79,22 @@ public class SpringApplicationJsonEnvironmentPostProcessor ...@@ -73,26 +79,22 @@ public class SpringApplicationJsonEnvironmentPostProcessor
String json = environment.resolvePlaceholders( String json = environment.resolvePlaceholders(
"${spring.application.json:${SPRING_APPLICATION_JSON:}}"); "${spring.application.json:${SPRING_APPLICATION_JSON:}}");
if (StringUtils.hasText(json)) { if (StringUtils.hasText(json)) {
try { processJson(environment, json);
JsonParser parser = JsonParserFactory.getJsonParser(); }
Map<String, Object> map = parser.parseMap(json); }
if (!map.isEmpty()) {
MapPropertySource source = new MapPropertySource( private void processJson(ConfigurableEnvironment environment, String json) {
"spring.application.json", flatten(map)); try {
MutablePropertySources sources = environment.getPropertySources(); JsonParser parser = JsonParserFactory.getJsonParser();
String name = findPropertySource(sources); Map<String, Object> map = parser.parseMap(json);
if (sources.contains(name)) { if (!map.isEmpty()) {
sources.addBefore(name, source); addJsonPropertySource(environment,
} new MapPropertySource("spring.application.json", flatten(map)));
else {
sources.addFirst(source);
}
}
}
catch (Exception e) {
logger.warn("Cannot parse JSON for spring.application.json: " + json, e);
} }
} }
catch (Exception ex) {
logger.warn("Cannot parse JSON for spring.application.json: " + json, ex);
}
} }
/** /**
...@@ -108,30 +110,20 @@ public class SpringApplicationJsonEnvironmentPostProcessor ...@@ -108,30 +110,20 @@ public class SpringApplicationJsonEnvironmentPostProcessor
private void flatten(String prefix, Map<String, Object> result, private void flatten(String prefix, Map<String, Object> result,
Map<String, Object> map) { Map<String, Object> map) {
if (prefix == null) { prefix = (prefix == null ? "" : prefix + ".");
prefix = ""; for (Map.Entry<String, Object> entry : map.entrySet()) {
} extract(prefix + entry.getKey(), result, entry.getValue());
else {
prefix = prefix + ".";
}
for (String key : map.keySet()) {
String name = prefix + key;
Object value = map.get(key);
extract(name, result, value);
} }
} }
@SuppressWarnings("unchecked")
private void extract(String name, Map<String, Object> result, Object value) { private void extract(String name, Map<String, Object> result, Object value) {
if (value instanceof Map) { if (value instanceof Map) {
@SuppressWarnings("unchecked") flatten(name, result, (Map<String, Object>) value);
Map<String, Object> nested = (Map<String, Object>) value;
flatten(name, result, nested);
} }
if (value instanceof Collection) { if (value instanceof Collection) {
@SuppressWarnings("unchecked")
Collection<Object> nested = (Collection<Object>) value;
int index = 0; int index = 0;
for (Object object : nested) { for (Object object : (Collection<Object>) value) {
extract(name + "[" + index + "]", result, object); extract(name + "[" + index + "]", result, object);
index++; index++;
} }
...@@ -141,12 +133,21 @@ public class SpringApplicationJsonEnvironmentPostProcessor ...@@ -141,12 +133,21 @@ public class SpringApplicationJsonEnvironmentPostProcessor
} }
} }
private void addJsonPropertySource(ConfigurableEnvironment environment,
PropertySource<?> source) {
MutablePropertySources sources = environment.getPropertySources();
String name = findPropertySource(sources);
if (sources.contains(name)) {
sources.addBefore(name, source);
}
else {
sources.addFirst(source);
}
}
private String findPropertySource(MutablePropertySources sources) { private String findPropertySource(MutablePropertySources sources) {
if (ClassUtils.isPresent( if (ClassUtils.isPresent(SERVLET_ENVIRONMENT_CLASS, null) && sources
"org.springframework.web.context.support.StandardServletEnvironment", .contains(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)) {
null)
&& sources
.contains(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)) {
return StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME; return StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME;
} }
......
...@@ -712,7 +712,6 @@ public class ConfigurationPropertiesBindingPostProcessorTests { ...@@ -712,7 +712,6 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
@EnableConfigurationProperties(PropertyWithoutConfigurationPropertiesAnnotation.class) @EnableConfigurationProperties(PropertyWithoutConfigurationPropertiesAnnotation.class)
public static class ConfigurationPropertiesWithoutAnnotation { public static class ConfigurationPropertiesWithoutAnnotation {
} }
public static class PropertyWithoutConfigurationPropertiesAnnotation { public static class PropertyWithoutConfigurationPropertiesAnnotation {
...@@ -726,6 +725,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests { ...@@ -726,6 +725,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
} }
...@@ -415,41 +415,49 @@ public class EnableConfigurationPropertiesTests { ...@@ -415,41 +415,49 @@ public class EnableConfigurationPropertiesTests {
@Configuration @Configuration
@EnableConfigurationProperties(TestProperties.class) @EnableConfigurationProperties(TestProperties.class)
protected static class TestConfiguration { protected static class TestConfiguration {
} }
@Configuration @Configuration
@EnableConfigurationProperties(StrictTestProperties.class) @EnableConfigurationProperties(StrictTestProperties.class)
protected static class StrictTestConfiguration { protected static class StrictTestConfiguration {
} }
@Configuration @Configuration
@EnableConfigurationProperties(EmbeddedTestProperties.class) @EnableConfigurationProperties(EmbeddedTestProperties.class)
protected static class EmbeddedTestConfiguration { protected static class EmbeddedTestConfiguration {
} }
@Configuration @Configuration
@EnableConfigurationProperties(IgnoreNestedTestProperties.class) @EnableConfigurationProperties(IgnoreNestedTestProperties.class)
protected static class IgnoreNestedTestConfiguration { protected static class IgnoreNestedTestConfiguration {
} }
@Configuration @Configuration
@EnableConfigurationProperties(ExceptionIfInvalidTestProperties.class) @EnableConfigurationProperties(ExceptionIfInvalidTestProperties.class)
protected static class ExceptionIfInvalidTestConfiguration { protected static class ExceptionIfInvalidTestConfiguration {
} }
@Configuration @Configuration
@EnableConfigurationProperties(NoExceptionIfInvalidTestProperties.class) @EnableConfigurationProperties(NoExceptionIfInvalidTestProperties.class)
protected static class NoExceptionIfInvalidTestConfiguration { protected static class NoExceptionIfInvalidTestConfiguration {
} }
@Configuration @Configuration
@EnableConfigurationProperties(DerivedProperties.class) @EnableConfigurationProperties(DerivedProperties.class)
protected static class DerivedConfiguration { protected static class DerivedConfiguration {
} }
@Configuration @Configuration
@EnableConfigurationProperties(NestedProperties.class) @EnableConfigurationProperties(NestedProperties.class)
protected static class NestedConfiguration { protected static class NestedConfiguration {
} }
@Configuration @Configuration
...@@ -467,6 +475,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -467,6 +475,7 @@ public class EnableConfigurationPropertiesTests {
@Configuration @Configuration
@ImportResource("org/springframework/boot/context/properties/testProperties.xml") @ImportResource("org/springframework/boot/context/properties/testProperties.xml")
protected static class DefaultXmlConfiguration { protected static class DefaultXmlConfiguration {
} }
@EnableConfigurationProperties @EnableConfigurationProperties
...@@ -483,16 +492,19 @@ public class EnableConfigurationPropertiesTests { ...@@ -483,16 +492,19 @@ public class EnableConfigurationPropertiesTests {
@EnableConfigurationProperties(External.class) @EnableConfigurationProperties(External.class)
@Configuration @Configuration
public static class AnotherExampleConfig { public static class AnotherExampleConfig {
} }
@EnableConfigurationProperties({ External.class, Another.class }) @EnableConfigurationProperties({ External.class, Another.class })
@Configuration @Configuration
public static class FurtherExampleConfig { public static class FurtherExampleConfig {
} }
@EnableConfigurationProperties({ SystemEnvVar.class }) @EnableConfigurationProperties({ SystemEnvVar.class })
@Configuration @Configuration
public static class SystemExampleConfig { public static class SystemExampleConfig {
} }
@ConfigurationProperties(prefix = "external") @ConfigurationProperties(prefix = "external")
...@@ -507,6 +519,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -507,6 +519,7 @@ public class EnableConfigurationPropertiesTests {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
@ConfigurationProperties(prefix = "another") @ConfigurationProperties(prefix = "another")
...@@ -521,11 +534,14 @@ public class EnableConfigurationPropertiesTests { ...@@ -521,11 +534,14 @@ public class EnableConfigurationPropertiesTests {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
@ConfigurationProperties(prefix = "spring_test_external") @ConfigurationProperties(prefix = "spring_test_external")
public static class SystemEnvVar { public static class SystemEnvVar {
private String val;
public String getVal() { public String getVal() {
return this.val; return this.val;
} }
...@@ -534,8 +550,6 @@ public class EnableConfigurationPropertiesTests { ...@@ -534,8 +550,6 @@ public class EnableConfigurationPropertiesTests {
this.val = val; this.val = val;
} }
private String val;
} }
@Component @Component
...@@ -552,19 +566,20 @@ public class EnableConfigurationPropertiesTests { ...@@ -552,19 +566,20 @@ public class EnableConfigurationPropertiesTests {
public String getName() { public String getName() {
return this.properties.name; return this.properties.name;
} }
} }
@Configuration @Configuration
@EnableConfigurationProperties(MoreProperties.class) @EnableConfigurationProperties(MoreProperties.class)
protected static class MoreConfiguration { protected static class MoreConfiguration {
}
}
@Configuration @Configuration
@EnableConfigurationProperties(InvalidConfiguration.class) @EnableConfigurationProperties(InvalidConfiguration.class)
protected static class InvalidConfiguration { protected static class InvalidConfiguration {
}
}
@ConfigurationProperties @ConfigurationProperties
protected static class NestedProperties { protected static class NestedProperties {
...@@ -605,6 +620,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -605,6 +620,7 @@ public class EnableConfigurationPropertiesTests {
} }
protected static class DerivedProperties extends BaseProperties { protected static class DerivedProperties extends BaseProperties {
} }
@ConfigurationProperties @ConfigurationProperties
...@@ -638,14 +654,17 @@ public class EnableConfigurationPropertiesTests { ...@@ -638,14 +654,17 @@ public class EnableConfigurationPropertiesTests {
@ConfigurationProperties(ignoreUnknownFields = false) @ConfigurationProperties(ignoreUnknownFields = false)
protected static class StrictTestProperties extends TestProperties { protected static class StrictTestProperties extends TestProperties {
} }
@ConfigurationProperties(prefix = "spring.foo") @ConfigurationProperties(prefix = "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
...@@ -704,6 +723,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -704,6 +723,7 @@ public class EnableConfigurationPropertiesTests {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
@ConfigurationProperties(locations = "${binding.location:classpath:name.yml}") @ConfigurationProperties(locations = "${binding.location:classpath:name.yml}")
...@@ -731,5 +751,7 @@ public class EnableConfigurationPropertiesTests { ...@@ -731,5 +751,7 @@ public class EnableConfigurationPropertiesTests {
public Map<String, String> getMymap() { public Map<String, String> getMymap() {
return this.mymap; return this.mymap;
} }
} }
} }
...@@ -25,6 +25,8 @@ import org.springframework.core.env.StandardEnvironment; ...@@ -25,6 +25,8 @@ import org.springframework.core.env.StandardEnvironment;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
/** /**
* Tests for {@link SpringApplicationJsonEnvironmentPostProcessor}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class SpringApplicationJsonEnvironmentPostProcessorTests { public class SpringApplicationJsonEnvironmentPostProcessorTests {
......
...@@ -32,7 +32,6 @@ import static org.junit.Assert.assertNotNull; ...@@ -32,7 +32,6 @@ import static org.junit.Assert.assertNotNull;
*/ */
public class LoggingApplicationListenerIntegrationTests { public class LoggingApplicationListenerIntegrationTests {
@Test @Test
public void loggingSystemRegisteredInTheContext() { public void loggingSystemRegisteredInTheContext() {
ConfigurableApplicationContext context = new SpringApplicationBuilder( ConfigurableApplicationContext context = new SpringApplicationBuilder(
...@@ -46,7 +45,6 @@ public class LoggingApplicationListenerIntegrationTests { ...@@ -46,7 +45,6 @@ public class LoggingApplicationListenerIntegrationTests {
} }
} }
@Component @Component
static class SampleService { static class SampleService {
...@@ -56,7 +54,7 @@ public class LoggingApplicationListenerIntegrationTests { ...@@ -56,7 +54,7 @@ public class LoggingApplicationListenerIntegrationTests {
SampleService(LoggingSystem loggingSystem) { SampleService(LoggingSystem loggingSystem) {
this.loggingSystem = loggingSystem; this.loggingSystem = loggingSystem;
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment