|
@@ -147,100 +147,6 @@ $ curl localhost:8080
|
147
|
147
|
Greetings from Spring Boot!
|
148
|
148
|
....
|
149
|
149
|
|
150
|
|
-== Switch from Tomcat to Jetty
|
151
|
|
-What if you prefer Jetty over Tomcat? Jetty and Tomcat are both compliant servlet containers, so it should be easy to switch. With Spring Boot, it is!
|
152
|
|
-
|
153
|
|
-Change your `build.gradle` to exclude Tomcat then add Jetty to the list of dependencies:
|
154
|
|
-
|
155
|
|
-[source,groovy]
|
156
|
|
-----
|
157
|
|
-include::complete/build.gradle[tag=jetty]
|
158
|
|
-----
|
159
|
|
-
|
160
|
|
-If you are using Maven, the changes look like this:
|
161
|
|
-
|
162
|
|
-[source,xml]
|
163
|
|
-----
|
164
|
|
-include::complete/pom.xml[tag=jetty]
|
165
|
|
-----
|
166
|
|
-
|
167
|
|
-This change isn't about comparing Tomcat vs. Jetty. Instead, it demonstrates how Spring Boot reacts to what is on your classpath. And by no means does it assert which servlet container is right for you.
|
168
|
|
-
|
169
|
|
-As you can see below, the code is the same as before:
|
170
|
|
-
|
171
|
|
-`src/main/java/hello/Application.java`
|
172
|
|
-[source,java]
|
173
|
|
-----
|
174
|
|
-include::complete/src/main/java/hello/Application.java[]
|
175
|
|
-----
|
176
|
|
-
|
177
|
|
-
|
178
|
|
-== Re-run the application
|
179
|
|
-
|
180
|
|
-Run the app again:
|
181
|
|
-
|
182
|
|
-[subs="attributes"]
|
183
|
|
-----
|
184
|
|
-./gradlew build && java -jar build/libs/{project_id}-0.1.0.jar
|
185
|
|
-----
|
186
|
|
-
|
187
|
|
-If you are using Maven, execute:
|
188
|
|
-
|
189
|
|
-[subs="attributes"]
|
190
|
|
-----
|
191
|
|
-mvn package && java -jar target/{project_id}-0.1.0.jar
|
192
|
|
-----
|
193
|
|
-
|
194
|
|
-Now check out the output:
|
195
|
|
-
|
196
|
|
-....
|
197
|
|
-Let's inspect the beans provided by Spring Boot:
|
198
|
|
-application
|
199
|
|
-beanNameHandlerMapping
|
200
|
|
-defaultServletHandlerMapping
|
201
|
|
-dispatcherServlet
|
202
|
|
-embeddedServletContainerCustomizerBeanPostProcessor
|
203
|
|
-faviconHandlerMapping
|
204
|
|
-faviconRequestHandler
|
205
|
|
-handlerExceptionResolver
|
206
|
|
-helloController
|
207
|
|
-hiddenHttpMethodFilter
|
208
|
|
-httpRequestHandlerAdapter
|
209
|
|
-jettyEmbeddedServletContainerFactory
|
210
|
|
-messageSource
|
211
|
|
-mvcContentNegotiationManager
|
212
|
|
-mvcConversionService
|
213
|
|
-mvcValidator
|
214
|
|
-org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration
|
215
|
|
-org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
|
216
|
|
-org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration
|
217
|
|
-org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$DispatcherServletConfiguration
|
218
|
|
-org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration$EmbeddedJetty
|
219
|
|
-org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration
|
220
|
|
-org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration
|
221
|
|
-org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter
|
222
|
|
-org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter$FaviconConfiguration
|
223
|
|
-org.springframework.boot.context.embedded.properties.ServerProperties
|
224
|
|
-org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor
|
225
|
|
-org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor
|
226
|
|
-org.springframework.context.annotation.internalAutowiredAnnotationProcessor
|
227
|
|
-org.springframework.context.annotation.internalCommonAnnotationProcessor
|
228
|
|
-org.springframework.context.annotation.internalConfigurationAnnotationProcessor
|
229
|
|
-org.springframework.context.annotation.internalRequiredAnnotationProcessor
|
230
|
|
-org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration
|
231
|
|
-propertySourcesBinder
|
232
|
|
-propertySourcesPlaceholderConfigurer
|
233
|
|
-requestMappingHandlerAdapter
|
234
|
|
-requestMappingHandlerMapping
|
235
|
|
-resourceHandlerMapping
|
236
|
|
-simpleControllerHandlerAdapter
|
237
|
|
-viewControllerHandlerMapping
|
238
|
|
-....
|
239
|
|
-
|
240
|
|
-There is little change from the previous output, except there is no longer a `tomcatEmbeddedServletContainerFactory`. Instead, there is a new `jettyEmbeddedServletContainer`.
|
241
|
|
-
|
242
|
|
-Otherwise, everything is the same, as it should be. Most beans listed above provide Spring MVC's production-grade features. Simply swapping one part, the servlet container, shouldn't cause a system-wide ripple.
|
243
|
|
-
|
244
|
150
|
== Add production-grade services
|
245
|
151
|
If you are building a web site for your business, you probably need to add some management services. Spring Boot provides several out of the box with its https://github.com/spring-projects/spring-boot/blob/master/spring-boot-actuator/README.md[actuator module], such as health, audits, beans, and more.
|
246
|
152
|
|