From a9b8563bb6baf997434a4a9cf0e1e3b5aca9034e Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 21 Jul 2014 14:07:29 +0100 Subject: [PATCH 1/6] Fix typo (fixes gh-1273) --- spring-boot-docs/src/main/asciidoc/howto.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 88afdcc90b..5b375812a8 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -420,7 +420,7 @@ that sets up the connector to be secure: @Override public void customize(ConfigurableEmbeddedServletContainer factory) { if(factory instanceof TomcatEmbeddedServletContainerFactory) { - customizeTomcat((TomcatEmbeddedServletContainerFactory) factory)); + customizeTomcat((TomcatEmbeddedServletContainerFactory) factory); } } From 300e570f68fae6417a45b423f40d45fd37036735 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 21 Jul 2014 15:08:53 +0100 Subject: [PATCH 2/6] Reverse priority of property sources when extracting sub properties Fixes gh-1259 --- .../boot/bind/PropertySourceUtils.java | 2 +- .../bind/RelaxedPropertyResolverTests.java | 38 +++++++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourceUtils.java b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourceUtils.java index 450acdeed7..b2a268bd86 100644 --- a/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourceUtils.java +++ b/spring-boot/src/main/java/org/springframework/boot/bind/PropertySourceUtils.java @@ -67,7 +67,7 @@ public abstract class PropertySourceUtils { .getPropertyNames()) { String key = PropertySourceUtils.getSubKey(name, rootPrefix, keyPrefixes); - if (key != null) { + if (key != null && !subProperties.containsKey(key)) { subProperties.put(key, source.getProperty(name)); } } diff --git a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java index dbd1ac4020..4fbdfcf54c 100644 --- a/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/bind/RelaxedPropertyResolverTests.java @@ -16,20 +16,24 @@ package org.springframework.boot.bind; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + import java.util.LinkedHashMap; import java.util.Map; +import java.util.Properties; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.env.StandardEnvironment; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - /** * Tests for {@link RelaxedPropertyResolver}. * @@ -173,4 +177,30 @@ public class RelaxedPropertyResolverTests { assertThat(subProperties.get("a.c"), equalTo((Object) "2")); assertThat(subProperties.get("a.d"), equalTo((Object) "3")); } + + @Test + public void testPropertySource() throws Exception { + Properties properties; + PropertiesPropertySource propertySource; + String propertyPrefix = "spring.datasource."; + String propertyName = "password"; + String fullPropertyName = propertyPrefix + propertyName; + StandardEnvironment environment = new StandardEnvironment(); + MutablePropertySources sources = environment.getPropertySources(); + properties = new Properties(); + properties.put(fullPropertyName, "systemPassword"); + propertySource = new PropertiesPropertySource("system", properties); + sources.addLast(propertySource); + properties = new Properties(); + properties.put(fullPropertyName, "propertiesPassword"); + propertySource = new PropertiesPropertySource("properties", properties); + sources.addLast(propertySource); + RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver( + environment, propertyPrefix); + String directProperty = propertyResolver.getProperty(propertyName); + Map subProperties = propertyResolver.getSubProperties(""); + String subProperty = (String) subProperties.get(propertyName); + assertEquals(directProperty, subProperty); + } + } From 16c2477da266f08beec6af034957a99981ea96b1 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 9 Jul 2014 15:57:22 +0200 Subject: [PATCH 3/6] Documentation update This commit fixes some inconsistent or outdated keys in the documentation. More specifically: * allowSessionOverride is no longer a template parameter * templateEncoding has been renamed to charSet * Groovy templates do not have the same configuration hierarchy, hence they don't share all settings * spring.data.elasticsearch.local does not seem to exist * flyway prefix and suffix should be sqlMigrationPrefix and suffix * spring.rabbitmq.virtualHost had a typo * endpoints.error.path is not a valid property * shell.command-path-patterns had a typo * spring.datasource.max-wait had a typo Fixes gh-1226 --- .../appendix-application-properties.adoc | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 51922f9a79..8909d2aa90 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -86,9 +86,9 @@ content into your application; rather pick only the properties that you need. # FREEMARKER ({sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[FreeMarkerAutoConfiguration]) spring.freemarker.allowRequestOverride=false - spring.freemarker.allowSessionOverride=false spring.freemarker.cache=true spring.freemarker.checkTemplateLocation=true + spring.freemarker.charSet=UTF-8 spring.freemarker.contentType=text/html spring.freemarker.exposeRequestAttributes=false spring.freemarker.exposeSessionAttributes=false @@ -97,26 +97,23 @@ content into your application; rather pick only the properties that you need. spring.freemarker.requestContextAttribute= spring.freemarker.settings.*= spring.freemarker.suffix=.ftl - spring.freemarker.templateEncoding=UTF-8 spring.freemarker.templateLoaderPath=classpath:/templates/ spring.freemarker.viewNames= # whitelist of view names that can be resolved # GROOVY TEMPLATES ({sc-spring-boot-autoconfigure}/groovy/template/GroovyTemplateAutoConfiguration.{sc-ext}[GroovyTemplateAutoConfiguration]) - spring.groovy.template.allowRequestOverride=false - spring.groovy.template.allowSessionOverride=false spring.groovy.template.cache=true + spring.groovy.template.charSet=UTF-8 spring.groovy.template.configuration.*= # See Groovy's TemplateConfiguration spring.groovy.template.contentType=text/html spring.groovy.template.prefix=classpath:/templates/ spring.groovy.template.suffix=.tpl - spring.groovy.template.templateEncoding=UTF-8 spring.groovy.template.viewNames= # whitelist of view names that can be resolved # VELOCITY TEMPLATES ({sc-spring-boot-autoconfigure}/velocity/VelocityAutoConfiguration.{sc-ext}[VelocityAutoConfiguration]) spring.velocity.allowRequestOverride=false - spring.velocity.allowSessionOverride=false spring.velocity.cache=true spring.velocity.checkTemplateLocation=true + spring.velocity.charSet=UTF-8 spring.velocity.contentType=text/html spring.velocity.dateToolAttribute= spring.velocity.exposeRequestAttributes=false @@ -128,7 +125,6 @@ content into your application; rather pick only the properties that you need. spring.velocity.requestContextAttribute= spring.velocity.resourceLoaderPath=classpath:/templates/ spring.velocity.suffix=.vm - spring.velocity.templateEncoding=UTF-8 spring.velocity.viewNames= # whitelist of view names that can be resolved # INTERNATIONALIZATION ({sc-spring-boot-autoconfigure}/MessageSourceAutoConfiguration.{sc-ext}[MessageSourceAutoConfiguration]) @@ -177,7 +173,7 @@ content into your application; rather pick only the properties that you need. spring.datasource.test-while-idle= spring.datasource.time-between-eviction-runs-millis= spring.datasource.min-evictable-idle-time-millis= - spring.datasource.max-wait-millis= + spring.datasource.max-wait= # MONGODB ({sc-spring-boot-autoconfigure}/mongo/MongoProperties.{sc-ext}[MongoProperties]) spring.data.mongodb.host= # the db host @@ -204,7 +200,6 @@ content into your application; rather pick only the properties that you need. # ELASTICSEARCH ({sc-spring-boot-autoconfigure}/elasticsearch/ElasticsearchProperties.{sc-ext}[ElasticsearchProperties}]) spring.data.elasticsearch.cluster-name= # The cluster name (defaults to elasticsearch) spring.data.elasticsearch.cluster-nodes= # The address(es) of the server node (comma-separated; if not specified starts a client node) - spring.data.elasticsearch.local=true # if local mode should be used with client nodes spring.data.elasticsearch.repositories.enabled=true # if spring data repository support is enabled @@ -213,8 +208,8 @@ content into your application; rather pick only the properties that you need. flyway.locations=classpath:db/migrations # locations of migrations scripts flyway.schemas= # schemas to update flyway.initVersion= 1 # version to start migration - flyway.prefix=V - flyway.suffix=.sql + flyway.sql-migration-prefix=V + flyway.sql-migration-suffix=.sql flyway.enabled=true flyway.url= # JDBC url if you want Flyway to create its own DataSource flyway.user= # JDBC username if you want Flyway to create its own DataSource @@ -236,7 +231,7 @@ content into your application; rather pick only the properties that you need. spring.rabbitmq.addresses= # connection addresses (e.g. myhost:9999,otherhost:1111) spring.rabbitmq.username= # login user spring.rabbitmq.password= # login password - spring.rabbitmq.virtualhost= + spring.rabbitmq.virtualHost= spring.rabbitmq.dynamic= # REDIS ({sc-spring-boot-autoconfigure}/redis/RedisProperties.{sc-ext}[RedisProperties]) @@ -356,7 +351,6 @@ content into your application; rather pick only the properties that you need. endpoints.jolokia.path=jolokia endpoints.jolokia.sensitive=true endpoints.jolokia.enabled=true # when using Jolokia - endpoints.error.path=/error # JMX ENDPOINT ({sc-spring-boot-actuator}/autoconfigure/EndpointMBeanExportProperties.{sc-ext}[EndpointMBeanExportProperties]) endpoints.jmx.enabled=true @@ -370,7 +364,7 @@ content into your application; rather pick only the properties that you need. # REMOTE SHELL shell.auth=simple # jaas, key, simple, spring shell.command-refresh-interval=-1 - shell.command-path-pattern= # classpath*:/commands/**, classpath*:/crash/commands/** + shell.command-path-patterns= # classpath*:/commands/**, classpath*:/crash/commands/** shell.config-path-patterns= # classpath*:/crash/* shell.disabled-plugins=false # don't expose plugins shell.ssh.enabled= # ssh settings ... From 5e02ee6974c76451fc359fbe86e61312579166cb Mon Sep 17 00:00:00 2001 From: ddebree Date: Thu, 17 Jul 2014 20:44:31 +0200 Subject: [PATCH 4/6] Add java options for Heroku Procfile Added $JAVA_OPTS variable to the sample Heroku Procfile. If this is left out it can cause memory issues when the app starts. Fixes gh-1266 --- spring-boot-docs/src/main/asciidoc/cloud-deployment.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-docs/src/main/asciidoc/cloud-deployment.adoc b/spring-boot-docs/src/main/asciidoc/cloud-deployment.adoc index 2aa5c436df..4d76c266b4 100644 --- a/spring-boot-docs/src/main/asciidoc/cloud-deployment.adoc +++ b/spring-boot-docs/src/main/asciidoc/cloud-deployment.adoc @@ -153,7 +153,7 @@ for our starter REST application: [indent=0] ---- - web: java -Dserver.port=$PORT -jar target/demo-0.0.1-SNAPSHOT.jar + web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/demo-0.0.1-SNAPSHOT.jar ---- Spring Boot makes `-D` arguments available as properties accessible from a Spring From 99b3240ab270a935061b4ac68fe59053cccfcc8c Mon Sep 17 00:00:00 2001 From: Christian Dupuis Date: Mon, 21 Jul 2014 16:11:38 +0200 Subject: [PATCH 5/6] Ensure custom HTTP code mappings for /health don't remove default mappings Previously any custom http code mapping would remove the default mappings. With this commit the behaviour is changed so that default mappings will stay if a custom mapping is registered. Certainly a default mapping can be overridden. fixes #1264 --- .../EndpointWebMvcAutoConfiguration.java | 2 +- .../actuate/endpoint/mvc/HealthMvcEndpoint.java | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java index 5e49ac59f7..3c7fc0ed90 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/EndpointWebMvcAutoConfiguration.java @@ -157,7 +157,7 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware, public HealthMvcEndpoint healthMvcEndpoint(HealthEndpoint delegate) { HealthMvcEndpoint healthMvcEndpoint = new HealthMvcEndpoint(delegate); if (this.healthMvcEndpointProperties.getMapping() != null) { - healthMvcEndpoint.setStatusMapping(this.healthMvcEndpointProperties + healthMvcEndpoint.addStatusMapping(this.healthMvcEndpointProperties .getMapping()); } return healthMvcEndpoint; diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java index 2bf10fbdce..532f972920 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/HealthMvcEndpoint.java @@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody; /** * Adapter to expose {@link HealthEndpoint} as an {@link MvcEndpoint}. - * + * * @author Christian Dupuis * @since 1.1.0 */ @@ -50,7 +50,7 @@ public class HealthMvcEndpoint extends EndpointMvcAdapter { } /** - * Set specific status mappings + * Set specific status mappings. * @param statusMapping a map of status code to {@link HttpStatus} */ public void setStatusMapping(Map statusMapping) { @@ -59,7 +59,16 @@ public class HealthMvcEndpoint extends EndpointMvcAdapter { } /** - * Add a status mapping to the existing set + * Add specfic status mappings to the existing set. + * @param statusMapping a map of status code to {@link HttpStatus} + */ + public void addStatusMapping(Map statusMapping) { + Assert.notNull(statusMapping, "StatusMapping must not be null"); + this.statusMapping.putAll(statusMapping); + } + + /** + * Add a status mapping to the existing set. * @param status the status to map * @param httpStatus the http status */ @@ -70,7 +79,7 @@ public class HealthMvcEndpoint extends EndpointMvcAdapter { } /** - * Add a status mapping to the existing set + * Add a status mapping to the existing set. * @param statusCode the status code to map * @param httpStatus the http status */ From ac2ab39a540273f33c20454b0a175b043c8a31a2 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 21 Jul 2014 22:22:36 +0100 Subject: [PATCH 6/6] Use class name not value to support non-Hibernate JPA vendors With this change I got a simple Eclipselink version of the data-jpa sample working. I'll push that when I get time to research it a bit more (I needed to set up a Java agent so either that might be a problem for our integration tests if we can't work around it). Fixes gh-1268. --- .../boot/autoconfigure/orm/jpa/JpaProperties.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java index a868ce68de..bc0c8b5034 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaProperties.java @@ -116,7 +116,7 @@ public class JpaProperties { private Class namingStrategy; - private static Class DEFAULT_NAMING_STRATEGY = SpringNamingStrategy.class; + private static String DEFAULT_NAMING_STRATEGY = "org.springframework.boot.orm.jpa.SpringNamingStrategy"; private String ddlAuto; @@ -152,7 +152,7 @@ public class JpaProperties { } else if (this.namingStrategy == null) { result.put("hibernate.ejb.naming_strategy", - DEFAULT_NAMING_STRATEGY.getName()); + DEFAULT_NAMING_STRATEGY); } String ddlAuto = getOrDeduceDdlAuto(existing, dataSource); if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {