From e19bfd92512c578cee75e7a2d9d4809fa70eddce Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 19 Jan 2015 14:20:30 +0000 Subject: [PATCH] Document how to use Tomcat 7 or Jetty 8 with Gradle Previously, the documentation only provided examples of the required configuration for Maven users. This commit adds equivalent configuration snippets for those using Gradle. It also removes the recommendation to override the version of the Servlet API as this is unnecessary. The pom files for the Jetty 8 and Tomcat 7 samples have also been updated accordingly. Closes gh-2346 --- spring-boot-docs/src/main/asciidoc/howto.adoc | 81 ++++++++++++++++--- .../spring-boot-sample-jetty8/pom.xml | 1 - .../spring-boot-sample-tomcat7-jsp/pom.xml | 1 - 3 files changed, 72 insertions(+), 11 deletions(-) diff --git a/spring-boot-docs/src/main/asciidoc/howto.adoc b/spring-boot-docs/src/main/asciidoc/howto.adoc index 6ee4bf6b062..76455e057c8 100644 --- a/spring-boot-docs/src/main/asciidoc/howto.adoc +++ b/spring-boot-docs/src/main/asciidoc/howto.adoc @@ -604,8 +604,8 @@ Example in Gradle: } dependencies { - compile("org.springframework.boot:spring-boot-starter-web:{spring-boot-version}") - compile("org.springframework.boot:spring-boot-starter-undertow:{spring-boot-version}") + compile 'org.springframework.boot:spring-boot-starter-web:{spring-boot-version}") + compile 'org.springframework.boot:spring-boot-starter-undertow:{spring-boot-version}") // ... } ---- @@ -653,16 +653,20 @@ add a listener to the `Builder`: === Use Tomcat 7 Tomcat 7 works with Spring Boot, but the default is to use Tomcat 8. If you cannot use Tomcat 8 (for example, because you are using Java 1.6) you will need to change your -classpath to reference Tomcat 7 and Servlet API 3.0. +classpath to reference Tomcat 7 . -If you are using the starter poms and parent you can just change the version properties, -e.g. for a simple webapp or service: + + +==== Use Tomcat 7 with Maven +[[howto-use-tomcat-7-maven]] + +If you are using the starter poms and parent you can just change the Tomcat version +property, e.g. for a simple webapp or service: [source,xml,indent=0,subs="verbatim,quotes,attributes"] ---- 7.0.56 - 3.0.1 ... @@ -676,12 +680,42 @@ e.g. for a simple webapp or service: +==== Use Tomcat 7 with Gradle +[[howto-use-tomcat-7-gradle]] + +You can use a resolution strategy to change the versions of the Tomcat dependencies, +e.g. for a simple webapp or service: + +[source,groovy,indent=0,subs="verbatim,quotes,attributes"] +---- + configurations.all { + resolutionStrategy { + eachDependency { + if (it.requested.group == 'org.apache.tomcat.embed') { + it.useVersion '7.0.56' + } + } + } + } + + dependencies { + compile 'org.springframework.boot:spring-boot-starter-web' + } +---- + + + [[howto-use-jetty-8]] === Use Jetty 8 Jetty 8 works with Spring Boot, but the default is to use Jetty 9. If you cannot use Jetty 9 (for example, because you are using Java 1.6) you will need to change your -classpath to reference Jetty 8 and Servlet API 3.0. You will also need to exclude -Jetty's WebSocket-related dependencies. +classpath to reference Jetty 8. You will also need to exclude Jetty's WebSocket-related +dependencies. + + + +[[howto-use-jetty-8-maven]] +==== Use Jetty 8 with Maven If you are using the starter poms and parent you can just add the Jetty starter with the required WebSocket exclusion and change the version properties, e.g. for a simple @@ -692,7 +726,6 @@ webapp or service: 8.1.15.v20140411 2.2.0.v201112011158 - 3.0.1 @@ -720,6 +753,36 @@ webapp or service: +[[howto-use-jetty-8-gradle]] +==== Use Jetty 8 with Gradle + +You can use a resolution strategy to change the version of the Jetty dependencies, e.g. +for a simple webapp or service: + +[source,groovy,indent=0,subs="verbatim,quotes,attributes"] +---- + configurations.all { + resolutionStrategy { + eachDependency { + if (it.requested.group == 'org.eclipse.jetty') { + it.useVersion '8.1.15.v20140411' + } + } + } + } + + dependencies { + compile ('org.springframework.boot:spring-boot-starter-web') { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' + } + compile ('org.springframework.boot:spring-boot-starter-jetty') { + exclude group: 'org.eclipse.jetty.websocket' + } + } +---- + + + [[howto-create-websocket-endpoints-using-serverendpoint]] === Create WebSocket endpoints using @ServerEndpoint If you want to use `@ServerEndpoint` in a Spring Boot application that used an embedded diff --git a/spring-boot-samples/spring-boot-sample-jetty8/pom.xml b/spring-boot-samples/spring-boot-sample-jetty8/pom.xml index 33120ca77f1..7907c47a301 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8/pom.xml +++ b/spring-boot-samples/spring-boot-sample-jetty8/pom.xml @@ -19,7 +19,6 @@ ${basedir}/../.. 8.1.15.v20140411 2.2.0.v201112011158 - 3.0.1 diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/pom.xml b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/pom.xml index b88b10f4ce1..259e59ec6c4 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/pom.xml +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/pom.xml @@ -20,7 +20,6 @@ ${basedir}/../.. / 7.0.56 - 3.0.1 1.7