diff --git a/docs/howto.md b/docs/howto.md index 3f4a1424fe0..52981c1d041 100644 --- a/docs/howto.md +++ b/docs/howto.md @@ -161,6 +161,39 @@ are quite rich so once you have access to the of ways. Or the nuclear option is to add your own `JettyEmbeddedServletContainerFactory`. +## Use Jetty 9 + +Jetty 9 works with Spring Boot, but the default is to use Jetty 8 (so +we can support Java 1.6 out of the box). You should only need to +change the classpath to use Jetty 9 for it to work. + +If you are using the starter poms and parent you can just add the +Jetty starter and change the version properties, e.g. for a simple +webapp or service: + + + 1.7 + 9.1.0.v20131115 + 3.1.0 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-jetty + + + ## Terminate SSL in Tomcat Add a `EmbeddedServletContainerCustomizer` and in that add a @@ -733,7 +766,7 @@ In Spring Boot you can also set the active profile in spring.profiles.active: production ``` -A value set this is replaced by the System property or environment +A value set this way is replaced by the System property or environment variable setting, but not by the `SpringApplicationBuilder.profiles()` method. Thus the latter Java API can be used to augment the profiles without changing the defaults. @@ -756,16 +789,18 @@ added using the default locations, but have lower priority than system properties, environment variables or the command line. You can also provide System properties (or environment variables) to -change the default behaviour: +change the behaviour: * `config.name` (`CONFIG_NAME`), defaults to `application` as the root of the file name -* `config.location` (`CONFIG_LOCATION`) is a comma-separated list of - files to load. A separate `Environment` property source is set up - for each document found, so the priority order is most significant - first. Defaults to - `file:./application.properties,classpath:application.properties`. If - YAML is used then those files are also added to the list by default. +* `config.location` (`CONFIG_LOCATION`) is file to load (e.g. a + classpath resource or a URL). A separate `Environment` property + source is set up for this document and it can be overridden by + system properties, environment variables or the command line. + +No matter what you set in the environment, Spring Boot will always +load `application.properties` as described above. If YAML is used then +files with the ".yml" extension are also added to the list by default. See `ConfigFileApplicationContextInitializer` for more detail. diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java index 00f92e37c06..47039fdd40c 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java @@ -23,6 +23,7 @@ import org.eclipse.jetty.server.Server; import org.springframework.boot.context.embedded.EmbeddedServletContainer; import org.springframework.boot.context.embedded.EmbeddedServletContainerException; import org.springframework.util.Assert; +import org.springframework.util.ReflectionUtils; /** * {@link EmbeddedServletContainer} that can be used to control an embedded Jetty server. @@ -86,7 +87,7 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer { Connector[] connectors = this.server.getConnectors(); for (Connector connector : connectors) { connector.start(); - this.logger.info("Jetty started on port: " + connector.getLocalPort()); + this.logger.info("Jetty started on port: " + getLocalPort(connector)); } } catch (Exception ex) { @@ -95,6 +96,18 @@ public class JettyEmbeddedServletContainer implements EmbeddedServletContainer { } } + private String getLocalPort(Connector connector) { + try { + // Jetty 9 internals are different, but the method name is the same + return ((Integer) ReflectionUtils.invokeMethod( + ReflectionUtils.findMethod(connector.getClass(), "getLocalPort"), + connector)).toString(); + } + catch (Exception e) { + return "could not determine port ( " + e.getMessage() + ")"; + } + } + @Override public synchronized void stop() { try {