From 265a71229417e22ee81453107c49e7539230c5b6 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 25 Jan 2017 10:41:47 +0100 Subject: [PATCH 1/2] Fix keys format for embedded mongodb support Closes gh-8102 --- .../src/main/asciidoc/appendix-application-properties.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 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 3e2cded3644..bb5ac34a452 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -798,9 +798,9 @@ content into your application; rather pick only the properties that you need. # EMBEDDED MONGODB ({sc-spring-boot-autoconfigure}/mongo/embedded/EmbeddedMongoProperties.{sc-ext}[EmbeddedMongoProperties]) spring.mongodb.embedded.features=SYNC_DELAY # Comma-separated list of features to enable. - spring.mongodb.embedded.storage.databaseDir= # Directory used for data storage. - spring.mongodb.embedded.storage.oplogSize= # Maximum size of the oplog in megabytes. - spring.mongodb.embedded.storage.replSetName= # Name of the replica set. + spring.mongodb.embedded.storage.database-dir= # Directory used for data storage. + spring.mongodb.embedded.storage.oplog-size= # Maximum size of the oplog in megabytes. + spring.mongodb.embedded.storage.repl-set-name= # Name of the replica set. spring.mongodb.embedded.version=2.6.10 # Version of Mongo to use. # REDIS ({sc-spring-boot-autoconfigure}/data/redis/RedisProperties.{sc-ext}[RedisProperties]) From bfee21730c2e19e44a11e605e4e243c4db7cc9da Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 25 Jan 2017 11:21:17 +0000 Subject: [PATCH 2/2] Detect path of exploded war correctly on Windows Previously, AbstractEmbeddedServletContainerFactory detected an exploded war by looking for `/WEB-INF/` in the path of its code source's location. This failed on Windows due to the use of `\` rather than `/` separators. This commit updates AbstractEmbeddedServletContainerFactory to uses the OS's separator rather than hardcoding `/`. Closes gh-8100 --- ...stractEmbeddedServletContainerFactory.java | 22 ++++++++++++------- ...tEmbeddedServletContainerFactoryTests.java | 20 ++++++++++++++++- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java index e870db76383..b2c14c9be6a 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 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. @@ -83,15 +83,21 @@ public abstract class AbstractEmbeddedServletContainerFactory } private File getExplodedWarFileDocumentRoot() { - File file = getCodeSourceArchive(); + return getExplodedWarFileDocumentRoot(getCodeSourceArchive()); + } + + File getExplodedWarFileDocumentRoot(File codeSourceFile) { if (this.logger.isDebugEnabled()) { - this.logger.debug("Code archive: " + file); + this.logger.debug("Code archive: " + codeSourceFile); } - if (file != null && file.exists() - && file.getAbsolutePath().contains("/WEB-INF/")) { - String path = file.getAbsolutePath(); - path = path.substring(0, path.indexOf("/WEB-INF/")); - return new File(path); + if (codeSourceFile != null && codeSourceFile.exists()) { + String path = codeSourceFile.getAbsolutePath(); + int webInfPathIndex = path + .indexOf(File.separatorChar + "WEB-INF" + File.separatorChar); + if (webInfPathIndex >= 0) { + path = path.substring(0, webInfPathIndex); + return new File(path); + } } return null; } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index 5ce1d248e32..55c93af9c7b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -915,6 +915,24 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { assertThat(getCharset(Locale.ITALIAN)).isNull(); } + @Test + public void explodedWarFileDocumentRootWhenRunningFromExplodedWar() throws Exception { + AbstractEmbeddedServletContainerFactory factory = getFactory(); + File webInfClasses = this.temporaryFolder.newFolder("test.war", "WEB-INF", "lib", + "spring-boot.jar"); + File documentRoot = factory.getExplodedWarFileDocumentRoot(webInfClasses); + assertThat(documentRoot) + .isEqualTo(webInfClasses.getParentFile().getParentFile().getParentFile()); + } + + @Test + public void explodedWarFileDocumentRootWhenRunningFromPackagedWar() throws Exception { + AbstractEmbeddedServletContainerFactory factory = getFactory(); + File codeSourceFile = this.temporaryFolder.newFile("test.war"); + File documentRoot = factory.getExplodedWarFileDocumentRoot(codeSourceFile); + assertThat(documentRoot).isNull(); + } + protected abstract void addConnector(int port, AbstractEmbeddedServletContainerFactory factory);